How to call UI script from catalog client script?

Ujjwal Rana1
Kilo Contributor

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.

4 REPLIES 4

Joshwa Antony S
Mega Guru

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.

find_real_file.png

find_real_file.png

Refer: https://community.servicenow.com/community?id=community_question&sys_id=ed2fb4cadbea9f809d612926ca96...

https://community.servicenow.com/community?id=community_question&sys_id=9c6e0321dbdcdbc01dcaf3231f96...

https://community.servicenow.com/community?id=community_question&sys_id=c981cf29db98dbc01dcaf3231f96... (for scoped app)

Regards,

JAS

asifnoor
Kilo Patron

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

 

Prithviraj Howa
Kilo Expert

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

 

 

Megha Padale
Giga Guru

Hi Ujjwal,

Please refer this links, see if it helps you:

https://docs.servicenow.com/bundle/madrid-application-development/page/script/client-scripts/concept...

https://community.servicenow.com/community?id=community_question&sys_id=94f7cb2ddb1cdbc01dcaf3231f96...

If my answer is helpful to you, mark answer as helpful and correct.

Thanks,

Megha