Client script to default a value

Jen11
Tera Expert

Hello All,

I have a select box field, when the option Temporary is selected:

Jen11_0-1697217155206.png

I have another select box below this, I would like 'All Department' to default and make this field read only.

Jen11_1-1697217217860.png

How can i go about doing this? 

1 ACCEPTED SOLUTION

Hemanth M1
Giga Sage
Giga Sage

Hi @Jen11 , write a onChange catalog client scrpt as below:

HemanthM1_0-1697219906084.png

 

script : 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    //Type appropriate comment here, and begin script below

    if (newValue == "abc") { //replace bac with Temporary choice  value
        g_form.setValue("s2", "pqr"); //replace s2 - select box 2 variable name and PQR with All Department' value
        g_form.setReadOnly("s2", true); //replace s2 with select box varibale name
    }



}

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

View solution in original post

6 REPLIES 6

Hi @Jen11 ,

put else loop and clear the value as below

else{
g_form.setReadOnly(“s2”,false);

g_form.setClearValue(“s2”);
}

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

swathisarang98
Giga Sage
Giga Sage

Hi @Jen11,

 

You can create a simple UI policy as shown below ,

Screenshot 2023-10-13 at 11.30.19 PM.png

Screenshot 2023-10-13 at 11.39.38 PM.png

 

 

Script

function onCondition()
{
g_form.setReadOnly('variable_2',true);
g_form.setValue('variable_2','temporary');
 
}

 

 

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang