Need to hide a variable of type Label on a catalog item

abcmh
Giga Contributor

Hi,

I have a couple of variables on my catalog item that are of type Label.

i want to hide these 2 variables when a particular value is selected from a dropdown.

So i am wrote a script on the onchange event of the dropdown variable to hide labels but now it labels are always hidden. I want to display or hide them depeding on the value selected from the dropdown.

Here is the code.

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue == '') {

          return;

    }

val = g_form.getValue('upl_documenttype');

if (val == "DD254" || val == "CSCS" || val == "CDCG");

{

g_form.setDisplay('upl_lblpop', false);

}

//Type appropriate comment here, and begin script below

   

}

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Updated code here.



function onChange(control, oldValue, newValue, isLoading) {


    if (isLoading || newValue == '') {


          return;


    }




val = g_form.getValue('upl_documenttype');



if (val == "DD254" || val == "CSCS" || val == "CDCG");


{


g_form.setDisplay('upl_lblpop', false);


}


else


{


g_form.setDisplay('upl_lblpop', true);


}


//Type appropriate comment here, and begin script below


 


}


View solution in original post

4 REPLIES 4

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Updated code here.



function onChange(control, oldValue, newValue, isLoading) {


    if (isLoading || newValue == '') {


          return;


    }




val = g_form.getValue('upl_documenttype');



if (val == "DD254" || val == "CSCS" || val == "CDCG");


{


g_form.setDisplay('upl_lblpop', false);


}


else


{


g_form.setDisplay('upl_lblpop', true);


}


//Type appropriate comment here, and begin script below


 


}


I had added an else condition earlier but it gives a compilation error.



function onChange(control, oldValue, newValue, isLoading) {


    if (isLoading || newValue == '') {


          return;


    }




val = g_form.getValue('upl_documenttype');



if (val == "DD254" || val == "CSCS" || val == "CDCG");


{


g_form.setDisplay('upl_lblpop', false);


}


else


{


g_form.setDisplay('upl_lblpop', true);


}


//Type appropriate comment here, and begin script below


   


}


Could not save record because of a compile error: JavaScript parse error at line (12) column (6) problem = syntax error (<refname>; line 12)


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

The reason is you have ; in your if condition i.e if (val == "DD254" || val == "CSCS" || val == "CDCG"); should be if (val == "DD254" || val == "CSCS" || val == "CDCG")


nitin_kumar
Mega Guru

Hi Amol,



Add an else condition to make the label visible again



else


{


g_form.setDisplay('upl_lblpop', true);


}



Thanks,


Nitin.



Please Hit like, Helpful or Correct depending on the impact of the response