Help with UI Script.

Abhijit Das7
Tera Expert

Hi Everyone, 

 

I have created a UI Script in Custom Scope 'A' and I want to call this script into UI Action which is present in custom scope B. 

 

Is it Possible for me to call cross scope UI script into UI Action.

 

UI Script:

functionsUIscriptHelpers();
function functionsUIscriptHelpers() {
	function helper1() {
		alert("TEST helper1 FUNC")
	}
	functionsUIscriptHelpers.functionsUIscriptHelpers = helper1;
}

 

UI Action:

function onClickOfUIAction() {
	functionsUIscriptHelpers.helper1();
}

I cannot see the Alert message. Please guide how can I call cross scope UI Script into UI Action. And I want to know, can I send some variables also into this UI script. 

 

Thanks in advance.

 

 

1 ACCEPTED SOLUTION

@Abhijit Das7 

It works, you should be able to call UI script created in scope A from any outside scope

UI Script: Created in scope "01/23"

AnkurBawiskar_0-1748275307973.png

 

Called that UI Script from Client script in other scope "16Jan 001"

AnkurBawiskar_1-1748275365019.png

 

Output: It called that function and gave alert when onload form was opened for My Table present in scope "16Jan 001"

AnkurBawiskar_2-1748275470601.png

I hope I have answered your question.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

9 REPLIES 9

@Abhijit Das7 

you should find lot of OOTB UI scripts used in scoped app, you can check them

But I am not sure if cross scope UI script is allowed and if it works

search with client script contains ScriptLoader

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Abhijit Das7 

It works, you should be able to call UI script created in scope A from any outside scope

UI Script: Created in scope "01/23"

AnkurBawiskar_0-1748275307973.png

 

Called that UI Script from Client script in other scope "16Jan 001"

AnkurBawiskar_1-1748275365019.png

 

Output: It called that function and gave alert when onload form was opened for My Table present in scope "16Jan 001"

AnkurBawiskar_2-1748275470601.png

I hope I have answered your question.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Abhijit Das7 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

 

I used exact code used by you, but in place of client script I am using UI Action. I cannot see alert. Is it like I can call UI script in another scope from client script but not from UI Action.

 

And in console I am getting this error:

Refused to execute script from 'https://ven04333.service-now.com/x_cc_aa_spoke.MyScriptDesktop' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

 

Thanks

@Abhijit Das7 

Please check the configurations once.

It worked for me when called from UI action

AnkurBawiskar_1-1748322662718.png

 

AnkurBawiskar_0-1748322632051.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader