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

Ankur Bawiskar
Tera Patron
Tera Patron

@Abhijit Das7 

any reason not to create that UI script in the same scope as that of client script?

check this link

[SOLVED] How to call scoped UI script from catalog client script ? 

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 

 

Yes, we have a reason to create UI script in different scope. So, we will put UI script in Scope 'A' and we call this script into multiple scopes. Like UI action in scope 'B' will call this UI Script in scope 'A' and UI action in scope 'C' will call this UI script in scope 'A'. Basically, multiple UI action in different scopes will call this common UI Script.

 

Thanks in advance.

@Abhijit Das7 

did you check the link I shared?

It talks about using UI script in scoped app, see the same syntax works when it calls from other scope

any cross scope issue comes or not?

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 cannot see Script Loader working. In console I see '1'and '2'. I am not sure whether UI action is even calling UI Script.

 

UI Script:

/* eslint-disable no-mixed-spaces-and-tabs */
var x_fmc_ibfs = x_fmc_ibfs || {};

x_fmc_ibfs.MyScriptDesktop = (function() {
	"use strict";

	return {
		myUtilityFunction: function(myParameter1, myParameter2) {
			console.warn("Hello World!  myParameter1: " + myParameter1 + ".  myParameter2: " + myParameter2);
			return myParameter1 + myParameter2;
		},
		type:  "MyScriptDesktop"
	};
})();

UI Action:

function PopupITSM() {
   
   function myClientSide() {
		
		
		var myResult = MyScriptDesktop.myUtilityFunction("P1", "P2");
		alert("myResult: " + myResult);
		
	}

	console.warn("1");
	ScriptLoader.getScripts("MyScriptDesktop.jsdbx",myClientSide);
	console.warn("2");

        return;
}