Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Using Script in Set Value of Catalog UI Policy

Dinh Nguyen
Kilo Sage

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:

DinhNguyen_0-1764308201556.png

Catalog UI Policy Action:

DinhNguyen_1-1764308436922.pngDinhNguyen_2-1764308453055.png

 

Result:

DinhNguyen_3-1764308510206.png

 

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.

1 ACCEPTED SOLUTION

Thankyou @Deepak Shaerma  for response me.

I found that it depends on the data type of the variable to understand javascript:...

The variable I need to process is a reference, but when investigating, I used a string variable, so javascript:... did not work.

However, my problem has been resolved. Thank you.

View solution in original post

2 REPLIES 2

Deepak Shaerma
Kilo Sage
Kilo Sage

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



Thankyou @Deepak Shaerma  for response me.

I found that it depends on the data type of the variable to understand javascript:...

The variable I need to process is a reference, but when investigating, I used a string variable, so javascript:... did not work.

However, my problem has been resolved. Thank you.