How to call UI script from catalog client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2020 03:17 AM
How to call UI script from catalog client script in scoped application.
I know we can use "ScriptLoader" to call global client script. But in my case it is not working because I am using scoped application and both UI script and Client script is available in scoped app.
Can someone please suggest how to call UI scripts in scoped application.
Thanks in advance.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2020 03:36 AM
Hello,
You can mark a UI script as Global to make it available on any form in the system.
After you create this global UI script, you can call the function from any client script or UI policy you write.
https://community.servicenow.com/community?id=community_question&sys_id=c981cf29db98dbc01dcaf3231f96... (for scoped app)
Regards,
JAS

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2020 04:25 AM
Hi,
Is there any specific reason of why you want to call UI script in the client script. Whatever you can do in UI script, you can anyway achieve that in the client script.
If you have to call UI scrpt, then you need to make that UI script global, and making it global means that it will be executed on every page, which is not recommended.
So its best you do that in the client script itself instead of calling UI script.
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2020 04:47 AM
Hello Ujjwal,
First create the catalog item and the variable as "Name" and keep variable type as "Reference"
Then navigate to "UI Script"
Write below script in UI script:
function helloworld()
{
alert('This from UI policy');
}
Then in catalog item scroll to Catalog client Script --> New
1.Name:______
2.Applies to: A Catalog Item
3.Type: onChange
4.Catalog item: name of your catalog item
5.Variable name: variable you created
6.Applies on a Catalog Item view --> Checked
7.Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
helloworld();
}
8. Then "Try it"
9. When you change the Reference field "Name" the you will find alert message as "This from UI policy" in alert box
That means your client script is calling to UI Script.
Please mark answer as Correct/ Helpful, if applicable. Thanks!
If you not get the answer then let me know.
Warm Regards,
Prithviraj Howal
SNOW Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2020 05:19 AM
Hi Ujjwal,
Please refer this links, see if it helps you:
If my answer is helpful to you, mark answer as helpful and correct.
Thanks,
Megha