Issue with catalog client script.

Jen11
Tera Expert

I have a catalog client script so for the question 'What is the nature of your request?' is 'Temporary Alternate Approver' then the question 'Please indicate where the approver needs to be updated' auto populates to 'All Departments' and becomes read only.  This is the onChange catalog client script i have: (Which works fine)

 

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

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

    } else {
    g_form.setValue("u_approver_needs_updated", "");
        g_form.setReadOnly("u_approver_needs_updated", false);
       
    }
 
I have another onChange catalog client script so when 'What is the Nature of your request?' is "add Approvers to Workflow' is selected then I want Specific Departments(s) to auto populate and make the field read only.  I have the following onChange catalog client script: (This one is not working, it is NOT auto populating or making the field read only)  I don't know what I am missing. If someone can please help me with this.
 
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;

    }

    if (newValue == "Add Approver to Workflow") { //replace bac with Temporary choice  value
        g_form.setValue("u_approver_needs_updated", "Specific Department(s)"); //replace s2 - select box 2 variable name and PQR with All Department' value
        g_form.setReadOnly("u_approver_needs_updated", true); //replace s2 with select box varibale name

    } else {
    g_form.setValue("u_approver_needs_updated", "");
        g_form.setReadOnly("u_approver_needs_updated", false);
       
    }
 
1 ACCEPTED SOLUTION

Ashutosh C J
Tera Guru

Hi @Jen11 
The issue here is because of 2 client scripts that work on same field.
What happens here is,
The else loop in first client script holds true for the if loop in the second client script.
Lets take your 1st script 
 if (newValue == "Temporary Alternate Approver"
The opposite of this is (newValue ! = "Temporary Alternate Approver"). Now check the else loop of 1st client script which depicts that newValue can be "Add Approver to Workflow" as well.

That is why you should combine both the scripts and make 1 client script with if and else ladder structure.

View solution in original post

7 REPLIES 7

Ashutosh C J
Tera Guru

Hi @Jen11 
The issue here is because of 2 client scripts that work on same field.
What happens here is,
The else loop in first client script holds true for the if loop in the second client script.
Lets take your 1st script 
 if (newValue == "Temporary Alternate Approver"
The opposite of this is (newValue ! = "Temporary Alternate Approver"). Now check the else loop of 1st client script which depicts that newValue can be "Add Approver to Workflow" as well.

That is why you should combine both the scripts and make 1 client script with if and else ladder structure.

@Ashutosh C J  - I thought that would be the case.  Would you be able to help me with the script please?  How can i combine both?

@Jen11 
Please use this code

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

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

    } 
else if (newValue == "Add Approver to Workflow") { //replace bac with Temporary choice  value
        g_form.setValue("u_approver_needs_updated", "Specific Department(s)"); //replace s2 - select box 2 variable name and PQR with All Department' value
        g_form.setReadOnly("u_approver_needs_updated", true); //replace s2 with select box varibale name

    } else {
        g_form.setValue("u_approver_needs_updated", "");
        g_form.setReadOnly("u_approver_needs_updated", false);

    }

}


Yeah sure