Set Value in a Catalog UI Policy

JohnnieGross
Tera Expert

My scenario is that I have two fields that look up to the sys_user in a variable set.

 

They both get populated initially using javascript:gs_getUserID();

 

However, I have a checkbox that indicates that they are the same (as the initial default) and if the checkbox is unchecked then the second field clears out the value, which works just fine.

 

However, once the second value is cleared out and the user checks the box again that indicates that both user fields are the same, I would like the second field to populate again with the get user ID function.  

 

I was wondering if the Set Value in the Catalog UI Policy is able to accept the script?  If I type in the same script in the Set Value, it literally returns the value that I typed in instead of executing any script.  

 

Is the Set Value in a Catalog UI Policy only for literal values and not available to recognize a script?

 

Thank you!

2 ACCEPTED SOLUTIONS

Brad Bowman
Kilo Patron
Kilo Patron

To actually answer your question, yes - the new (Washington DC) Set Value feature can only accept literal values, not functions, javascript, or anything dynamic unfortunately.  Since this is a new feature, hopefully that will change to become more useful!  In the meantime, in the Execute if true script for the UI Policy, or if you decide to go the onChange Catalog Client Script route, you would either use

g_form.setValue('var_2', g_user.userID);

or

 g_form.setValue('var_2', g_form.getValue('var_1'); 

 

View solution in original post

Community Alums
Not applicable

Hi @JohnnieGross ,

I tried your problem in my PDI and it works for me I create onChange Client Script on checkbox and added below code 

 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below
	alert("Outside");
    if (newValue == 'No') {
		alert("inside if");
        g_form.setValue('user_name_2', ""); // Not Same
    } else{
		alert("inside else");
		g_form.setValue('user_name_2', g_form.getValue("user_name_1")); // Same
	}
}

 

SarthakKashyap_0-1726939398669.png

 

 

Result 

Initially

SarthakKashyap_0-1726939180822.png

When I hit NO

SarthakKashyap_1-1726939195515.png

When I again hit on YES

SarthakKashyap_2-1726939223530.png

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

View solution in original post

5 REPLIES 5

Although I got a alot out of other responses on my question, I used this example as a model to build out the various rules.  The rules actually belong to a variable set, so I wrote them from there.  My team and I are newbies to ServiceNow, and as we work on replicating our current service catalog from our legacy system to ServiceNow, we are working on ServiceNow learning courses plus collaborating in learning how things work amongst ourselves.  The community has been a great resource for filling in some of the blanks that we've been taking classes and could not recall or we haven't gotten there yet.  Thanks for all the helpful assistance.  Just from this one post, I've been able to write a complete series of rules to manipulate my variable set form.