Calling script include from UI Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2025 06:05 AM
Hi Everyone,
I am calling script include from UI Script. The script include is client callable and I placed gs.info in start of script include, but I cannot see gs.info in logs.
UI Script:
alert('This is test message');
var ar = new GlideAjax('x_cc_aa.myScriptInclude');
ar.addParam('sysparm_name', 'setDetails');
ar.addParam('sysparm_sysID', 'ed92e8d173d023002728660c4cf6a7bc');
ar.addParam('sysparm_table', 'incident');
ar.addParam('sysparm_contact_sysID', '77ad8176731313005754660c4cf6a7de');
ar.getXMLAnswer(setURLCallback);
function setURLCallback(response) {
alert(response);
var params = 'scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,width=1000,height=550,left=180,top=100';
var newWin = top.window.open(response, '_blank', params);
newWin.opener = null;
}
Script Include:
var myScriptInclude = Class.create();
myScriptInclude .prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
setDetails: function() {
var callUrl = "https://www.google.com/"
return callUrl;
},
type: 'myScriptInclude '
});
Can we call script include into UI Script.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2025 07:03 AM
Hello @Abhijit Das7 ,
Ok, thanks for the update.
Then how are you executing the code in the UI Script?
If it's not global then it won't run automatically.
There is no function defined in there that you would be able to call from a Client Script, for example.
Or do you want to run that code in a Portal UI? If so, have you included the UI Script as a JS Include in the portals's Theme?
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2025 09:08 AM - edited 05-27-2025 09:09 AM
Hi @Robert H @Ankur Bawiskar ,
I have a business requirement where we will have UI Action in custom scope A and UI Script and Script Include in custom scope B.
So, the client wants to make UI Script and Scipt Include to be generic and in fututre we will only make changes to UI action only.
Business reuirement process:
1. When I will click on UI Action (Scope A) it will send three parameters ( table name, sys_id and caller_id) to UI Script (Scope B).
2. The UI Script (Scope B) will call Script include (Scope B). In glide ajax addParam we will also send those above three parameters to Script Include. There in Script Include we will create custom URL and return this URL back to UI Script.
3. And using UI Script we will open the custom URL in new tab.
I know that I can directly complete the above process using UI Action and Script Include easily. Currently, we use UI Action and Script Include only to complete the above process.
But, now client wants less code in UI Action and more code in UI Script and Script Include as both of them will be generic and no changes will occur in them in near future.
And in future if any body wants to create a new UI action on any table, the person will be required to write very less code in UI Action as generic UI Script and Script Include will do the most work.
Please let me know if any more information required.
Thanks and regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2025 09:12 AM
your requirement is fine, but UI script function needs to be invoked and then only that function will invoke GlideAjax.
So your UI action will invoke UI script function -> that will invoke GlideAjax
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2025 10:01 AM
Hello @Abhijit Das7 ,
Thank you for the update, those are very important details.
Is this a UI Action in a Workspace? If so then you can rewrite your UI Script and then call it using the GlideUIScripts API, as shown in the example in the official docs.
But if the UI Action is used in the core UI then this won't work because the above API is not supported there, so you won't be able to call your UI Script from the UI Action client script. That would only be possible if the UI Script were "Global", but since it's in a scoped app that cannot be enabled either.
So in that case you'll have no choice but to put the code that you have put into the UI Script back into the UI Action. It's not a lot of code anyway, and it's not for customers to decide how something is to be implemented on such a deep technical level 😉
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2025 07:01 AM
If the 'Sandbox Enabled' field is checked on the script include, then you need to set the system property named 'glide.security.sandbox_no_logging' to false to see the gs.info() messages in the log.