Using Script in Set Value of Catalog UI Policy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hello everyone,
I’m wondering if I can write a script or call a Script Include in the 'Set Value' of a Catalog UI Policy Action ?
I tried the following as below, but it didn’t work:
Script Include:
Catalog UI Policy Action:
Result:
Is it feasible to make the 'Set Value' action more flexible here? If not, is there any documentation on this? I’ve researched but couldn’t find any.
Please someone help me. Thankyou so much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @Dinh Nguyen
No, it is not feasible to use javascript: or call a Script Include directly in the "Set Value" field of a Catalog UI Policy Action.
That specific field treats everything entered into it as a String (text). It does not possess the ability to evaluate JavaScript code. That is why your variable shows the literal text javascript:new global... instead of the result of the script.
Custom solution is to make your script include as client callable;
var TestSetValueCatalogUIP = Class.create();
// 1. Extend AbstractAjaxProcessor
TestSetValueCatalogUIP.prototype = Object.extendsObject(AbstractAjaxProcessor, {
// 2. Define the function name
getMyValue: function() {
return "This is from Script Include";
},
type: 'TestSetValueCatalogUIP'
});
In UI Policy , check the run script and in the "Execute if true" script field, use the following code
function onCondition() {
// Call the Script Include
var ga = new GlideAjax('TestSetValueCatalogUIP'); // Name of Script Include
ga.addParam('sysparm_name', 'getMyValue'); // Name of function
// Execute the call
ga.getXMLAnswer(function(answer) {
if (answer) {
g_form.setValue('comments', answer); // Set the value on the form
}
});
}
Happy to help! If this resolved your issue, kindly mark it as the correct answer and Helpful and close the thread so others can benefit too.
Warm Regards,
Deepak Sharma
Community Rising Star 2025
