Skip to Content
avatar image
Former Member

How to implement an confirmation dialog send by the OData backend in SAPUI5?

Hello everyone,

I'm currently working on a timekeeping app in SAPUI5. Now I'm planning to show a warning if an employee enters a value > 7.5 for his daily working hours. My question regarding this is how i can achieve this in the best way possible?

Currently i check the following in the CREATE_ENTITY method in the odata service:

 SELECT SUM( wrkhrs )
      FROM YPM_TIMESHEET
      INTO lv_sum_wrkhrs
      WHERE uname = ls_timesheet-uname
      AND wrkdat = ls_timesheet-wrkdat.

IF ( sy-subrc = 0 AND lv_sum_wrkhrs + ls_timesheet-wrkhrs > max_wrkhrs ).
        lr_message_cont->add_message(
        EXPORTING
        iv_msg_type = 'W'
        iv_msg_id = 'BUSINESS_WARNING'
        iv_msg_number = '008'
        iv_msg_text = text-008
        ).
ENDIF.

So I can display a warning on the client but how can i react according to his answer from the confirm dialog?

I thought of an additional parameter "skipWrkhrsWarning" i pass to the call of the create() method of sap.ui.model.odata.v2.ODataModel and check this parameter in the CREATE_ENTITY method. But I don't know if this is the right approach nor how to do it.

I'm glad for any kind of help!

Kind regards,

Marvin

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Jan 14 at 10:25 AM

    Hi Marvin,

    am i right, that you want to implement a popup, which says "Hey, you have more than 7.5 hours..."?

    When you call the CREATE_ENTITY, you have to create the entity, so you can only display a warning without the option to confirm and proceed.

    If you want to implement a real confirm option like "Hey, you have more than 7.5 hours, do you really want to save?" you have to do this in your UI5 App. After confirming the popup, you can call the CREATE_ENTITY. Here you have to do the validation if the user has already 7.5 hours or more in your UI5 coding. Maybee you can also create a function call which does only the validation in the backend and returns warnings if the user is over 7.5 hours. If the user confirms, call CREATE_ENTITY.

    How you display messages in UI5 coming from the gateway, refer to the following link: https://sapui5.hana.ondemand.com/#/topic/8956f0a223284d729900ebad4ca88356

    Regards
    Simon

    Add comment
    10|10000 characters needed characters exceeded

    • You can model as below -

      1. Create a function import which will fetch the maximum workschedule and does validation in backend. In case of any error (beyind threshold) , break the processing on UI and display the corresponding error message. Similarly do for warning (within threshold).

      2. Whenever the user manipulates the value in the workschedule fields trigger the step 1 function import to validate.

      3. Whenever the value state of UI is successfull then only trigger the create call which implicitly means user has accepted the warning message and requested to proceed with data creation. Again since the data can be fudged on UI so while creating do the same validation as step1 again.

  • Jan 14 at 07:48 AM

    as this is the validations on create/post, collect all the validation's results(If any errors/ warnings) from back end and send to front end(UI) with a meaning full message relevant to the context data. To catch the UI responses, add fields in the same element and share it through payload to process further or skip any validations specific to response. As per me, your idea is good to go...

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi P P,

      thanks for your reply! I didn't exactly understand what you meant by:

      To catch the UI responses, add fields in the same element and share it through payload to process further or skip any validations specific to response.

      Adding a new field to the entity of my timesheet as a flag for skipping warnings doesn't seem to be a good idea to me.

      Regards

      Marvin

  • Jan 16 at 03:34 AM

    Hi Marvin Gores,

    You can validate the value in the front end itself, rather than doing it in the create_entity method.

    Regards,

    Arjun Biswas

    Add comment
    10|10000 characters needed characters exceeded