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

Tuan Vu
Kilo Guru

Hi @Joy715 , Please make sure UI type of UI script is all, not desktop

Joy715
Tera Contributor

Hi! Thank you for your answer.

but it already set All type of UI Type.

Joy715_2-1669782329092.png

 

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!

Joy715
Tera Contributor

Thank you for answering my forgotten question!

It seems like I resolved it in a similar way to the solution you provided.