How to execute a scoped application UI script (not Global script) from UI policy run script,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2023 01:43 PM
I have a need to execute a scoped application UI script (not Global script) from UI policy run script, I have various options, but it won't execute. Below is a very simple sample script that I am trying to execute from UI policy run script and UI Script. Any guidance will help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2023 08:22 AM
Gotcha...sorry I couldn't be of more help! Glad to know its a specific problem, likely someone has a good answer -- btw, I saw this on your screenshots from a different post in the forum (the screenshots here are lowrez blurry, fyi)...for what it's worth, I noticed that it seems like you're passing the script's function in as a parameter to the call of the same script...not sure if that will work (but there's a lot I don't know 😉 )
Having said that,
UI scripts (servicenow.com) wrote:
Call a UI script from client-side code
Access UI scripts from within client-side code using the g_ui_scripts global object. For more information, see GlideUIScripts - Client.
Note: This class does not support UI scripts with the Global field set to true.
&&
GlideUIScripts - Client (servicenow.com) wrote:
function onLoad() { g_ui_scripts.getUIScript('myUIScript').then(function(script) { script.myUIScriptMethod(); }, function() { console.log('The script did not load'); }); }
...perhaps the "ScriptLoader" method is not available outside of global scope...?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2023 11:30 PM
Hi @mkm1 ,
If both ui script and ui policy are created in same application, then directly use the API name of the ui script which will be there in the ui script record in "API Name" field in the ui policy script and then can use dot and then name of the method to access the required methods specified in the ui script.
Example: sn_compliance.PolicyExceptionUtils.validateExceptionDuration("valid_from", "requested_valid_to", "requested_valid_to");
Amish Ranjan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2023 02:48 PM
Thanks for your suggestion. I tried calling it directly from UI policy script onCondition as shown below, it didn't work.
x_20949_ppt.ShowRelatedList.displayRelatedList('procurement_action', 'x_20949_ppt_awards_rejected');
I copied the UI script as it's into UI policy it works perfectly. But that's not I wanted; I want to reuse the UI script anywhere just calling the function with arguments.