Unable to properly call a UI Script from a Catalog Client Script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi,all.
I am trying to call a UI Script from a Catalog Client Script.
This development is being done within a custom application.
Here is the script. And error message is ''UI Script x_16799_test.TestUIScript is loaded but can not find dummyFunction or result is fraud. Result: null'
Could you please tell me why the UI Script cannot be called successfully?
Catalog Client Script
Type : onChange
UI Type : All
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var value = newValue;
var name = 'u_int_test';
var uiScriptName = 'x_16799_test.TestUIScript';
if (typeof g_ui_scripts !== 'undefined') {
// Workspace(WEP)
g_ui_scripts.getUIScript(uiScriptName).then(function(result) {
if (result && typeof result.dummyFunction === 'function') {
// if (result && typeof result.formatAndTruncateNumber === 'function') {
g_form.addInfoMessage('UI Script ' + uiScriptName + ' is loaded and find dummyFunction');
result.dummyFunction();
} else {
g_form.addInfoMessage('UI Script ' + uiScriptName + ' is loaded but can not find dummyFunction or result is fraud. Result: ' + JSON.stringify(result));
}
}).catch(function(error) {
g_form.addErrorMessage('UI script failed to load: ' + error);
});
}
}
UI Script
API:x_16799_test.TestUIScript
(function() {
return {
dummyFunction: function() {
// do noting
}
};
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@Tanushree Maiti
@Ankur Bawiskar
I successfully called it. Thank you very much.
However, another problem has occurred.
I tried to get the length of a string by writing str.length in the UI Script, but the following error message appeared in the console: "Cannot read properties of undefined (reading 'length')"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
'g_form.showFieldMsg' also cannot be used in UI Script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Glad to know that my approach worked for you.
Would you mind marking my response as correct and close the thread?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
you are running this script in native or portal?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
check this
[SOLVED] How to call scoped UI script from catalog client script ?
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
