Call UI Script from Catalog Client Scripts

Joy715
Tera Contributor

I need to run field auto-fill and validation for all catalog items.

So I made a common UI Script.

I try to call UI Script in Client Script but It shows this error message "(g_env) [SCRIPT:EXEC] Error while running Client Script "[Catalog Client Script Name]": ReferenceError: [UIScriptName] is not defined" in Service Portal.

Is there no way to call UI Script from Catalog Client Scripts for Service Portal?

 

UI Script :UIScriptName

 

var UIScriptName = Class.create();

UIScriptName.prototype = {
    ......
    validate: function(value) {
		var result= true;
		.....
		return result;
    },
    .....
};

 

 Catalog Client Script onChange

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    return new UIScriptName().validate(newValue);
}
	

 

 

1 ACCEPTED SOLUTION

Peter26
Tera Expert

Hi Joy,

 

In case you haven't yet found an answer, this post may help:

https://www.servicenow.com/community/developer-forum/solved-how-to-call-scoped-ui-script-from-catalo...

 

Apparently, this solution is specific to calls from Service Portal, and apparently won't work if the call is made from the Native UI, such as through the Record Producer "Try It". Still looking for a solution for the latter. 😕

 

Good luck!

View solution in original post

8 REPLIES 8

Sagar Pagar
Tera Patron

Hi @Joy715 ,

 

Try this in your catalog client scripts -

 

 

var result = UIScriptName().validate(newValue);

return result;

 

 

Also, take a look at - Call UI script from an Onload Catalog client script  

 

Thanks,
Sagar Pagar

The world works with ServiceNow

Hi! Thank you for your answer.

but it doesn't work..

Joy715_1-1669782238893.png

 

Hi @Joy715,

Have you added UI scripts in Service portals theme?

 

if not, please add it as follows. It will work.

Navigate to Service Portal > Themes and select the theme being used (Stock is the default).

Then, add the UI Script via the related list JS Includes at the bottom of the form (New).

 

SagarPagar_0-1669782808028.png

 

Note - UI Scripts ran from Service Portal have no access to g_form.

 
Thanks,
Sagar Pagar
The world works with ServiceNow

yep I did that... still same error 😭

Joy715_0-1669783403624.png