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

debendudas
Mega Sage

Hi @JohnnieGross ,

Please create an onChange client script for the check box.

 

If this solution helps you then, mark it as accepted solution ‌‌✔️ and give thumbs up 👍

Long Duong
Kilo Sage

Hi @JohnnieGross,

 

In theory, we can use the g_form.setValue () function in the UI policy. There are 2 fields for script in UI policy: "Execute if true" (run once the condition is true) and "Execute if false" (run once the condition is false). So, you can write the script on those fields based on your requirement.

 

However, If you want to populate some thing once the field changed, you should use the client script "on change" instead of that. Because UI policy should be used to make fields read only, visible, mandatory. Otherwise, the client script will be used to populate value for fields.

 

Please accept my solution and mark it helpful if it can help you. Thank you!

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'); 

 

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