- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 06:32 AM
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!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2024 05:34 AM - edited 09-21-2024 11:45 AM
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');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2024 10:21 AM - edited 09-21-2024 10:23 AM
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
}
}
Result
Initially
When I hit NO
When I again hit on YES
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2024 09:36 AM
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.