Skip to Content
0

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

Jan 11 at 01:53 PM

207

avatar image
Former Member

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Simon Perstorfer Jan 14 at 10:25 AM
1

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

Show 8 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Simon,

thanks for your reply! The thought to do the validation inside the UI5 app also came into my mind, but as the logic implemented on the client side can be manipulated, I still have to validate the entity inside the backend, right? So am I supposed to create a function import, which validates the entity and calls the CREAT_ENTITY method in case the validation succeeded?

Regards

Marvin

0

Hi Marvin,

you can implement validations which prevent the creation of records or inform the user about anything of course on the backend side. But validations which trigger a user action have to be done on client side. But the service can not trigger a user action like clicking ok on a popup. The validation which triggers this popup have to be done on the client side.

0
Former Member

Hi Simon,

i'm planning to do the validation on the backend side which should throw a warning in case the given value is higher than 7.5 hours. On client side i will catch this warning and set up a confirmation dialog. If the user wants to continue, i call the create entity method with a parameter which indicates that the warning should be skipped. My question now: How can I pass such a parameter to the OData create call:

https://sapui5.hana.ondemand.com/#/api/sap.ui.model.odata.v2.ODataModel

Please check method "create" in the upper url.

Regards

Marvin

0

Hi Marvin,

i don't think that this is the best way to do validations.

My suggestion is to implement a function import which you can call to validate the new entry on backend side before calling the create method. If the function call returns no error or all returned warnings are approved from the user, call the create method seperately. The best way would be of course to do all validations on client side but this is not always possible.

Regards
Simon

0
Former Member

Hi Simon,

but when i keep the create method free from validation code it would be possible to call the create method from client side without doing the validation first. In terms of security all validations done on clientside could be manipulated and therefore cannot secure the backend.

Do i get something wrong?

Regards

Marvin

0

Hi Marvin,

yes, thats right. Validations which prevent the creation of records have to be called also from the create method. But this are error (exceptions) cases which should not be suppressed by a flag.

And if you implement a flag which suppress the warnings or skipps the checks it's the same as if you do not call the checks in my opinion...

Regards
Simon

0
Former Member

Hi Simon,

of course it shouldn't be possible to skip any kind of errors I only want that the user is able to skip warnings. With that said I still don't know how I can pass a parameter for skipping warnings to the OData create call..

Regards

Marvin

0

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.

0
P P Jan 14 at 07:48 AM
0

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...

Show 1 Share
10 |10000 characters needed characters left 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

0
Arjun Biswas Jan 16 at 03:34 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded