Trigger UI Action from Client script - best practice and advice

magee
Kilo Sage

Hello community-

Need another set of eyes on my current situation

 

What I have today:

Close Task (sc_task) UI Action

Current UI Action functionality: We have a lot of checks up front in the Close Task UI Action that will check if field(s) have been populated on related tables. The checks are based on the SCTask short description.

 

Example: SCTask is related to table u_sw_request. If the UI Action Close Task is invoked, the UI Action will check if the procurement officer has identified an existing license to use or if procurement is needed. If the procurement officer has not completed the action needed on the u_sw_request table, an alert/field message is displayed. Again, this check is done all in the UI Action.

 

State set to Closed Skipped client script

Current client script functionality: Using the example above, if the user changes SC Task state to Closed Skipped, the client script simply  throws an alert to the user indicating that RITM001234 will be set to closed skipped and work can continue as planned. This script bypasses the check(s) to see if values are populated on related tables. There is NO check  when the state changes to Closed Skipped if required fields are populated (the check completed by the UI Action above).

 

In the example above, if the user select OK on the alert, there is NO check to see if the procurement officer completed the action on the related u_sw_request table record. 

 

Why this doesn't work: The action needed by the procurement officer in the related table record is needed later in the workflow. If the SC Task is set to Closed Skipped, the data needed on the related table record is not completed. Therefore, the workflow will get to a point where it's looking for a value on the u_sw_request record...sadly the value is not there because Closed Skipped was selected and our workflow throws an error.

 

Proposed future solution

Since all the 'checks' for mandatory fields (on related tables) are in the UI Action, I do not want to recreate the wheel by recreating that code into the client script that runs when the state changes to Closed Skipped.

What I'd like to happen is that when the user selects Closed Skipped, the UI Action is triggered and the mandatory fields on related tables is checked. The user is then told 'Hey, you have to complete a mandatory field on a related table, therefore, you cannot set this SC Task to Closed Skipped'

 

This would be easy if it was just 1 related table for 1 SC Task; unfortunately we have a lot checks on different related tables depending on the SC Task type. For example, if the SC Task is X, then check related table field 1. If the SC Task is Y, then check related table field 2, etc, etc.

 

Any ideas/suggestions are greatly appreciated

 

2 REPLIES 2

AndersBGS
Tera Patron

Hi @magee 

 

As I see it, you need to rebuild your logic so that a OnChange client script will trigger a glide Ajax where you then can have all your logic in a script include.

 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

magee
Kilo Sage

That's what I was thinking too. I'll get started on migrating the code to a script include and calling the script include from the UI Action and client script. STay tuned for updates