Client script to hide checkbox based off of user's department.

galavodasal
Giga Expert

Hey all, for whatever reason, UI policies to hide a checkbox will not work in our dev (Helsinki) or prod (Fuji) environments. So, I tried to create a client script to show the field "fast_corp" if the user's department in the "requested_for" field matches one of the four in the script. If not, hide the icon. So by default, the icon should be hidden until a user with one of the four departments matches the script.

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

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

  return;

  }

  var user = g_form.getValue('requested_for');

    if (user.department == "IT DEPARTMENTS" || user.department == "FINANCE DEPARTMENTS" || user.department == "Finance" || user.department == "SUPPLY") {

   

  g_form.setVisibile('fast_corp', 'true');

  }

else {

                g_form.setVisible('fast_corp');

          }

    }

I assume the dotwalking with the user variable didn't work.   Also, I tried removing the department condition and simply entered myself as the user and the checkbox was still showing up, no matter what user was entered.

1 ACCEPTED SOLUTION

Moreover I have   noticed that your onChange script is on fast_corp variable name. It should be   on requested_for not fast_corp.


View solution in original post

12 REPLIES 12

Abhinay Erra
Giga Sage

Here you go.try this



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


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


  return;


  }



  var user = g_form.getReference('requested_for',CallBack);


function CallBack(user){


    if (user.department == "IT DEPARTMENTS" || user.department == "FINANCE DEPARTMENTS" || user.department == "Finance" || user.department == "SUPPLY") {



  g_form.setDisplay('fast_corp', true);


  }


else {


                g_form.setDisplay('fast_corp',false);


          }


}


    }


Nope, the checkbox still shows no matter what. Also, do I have to use the .toLowerCase() after the user.department, and should I use quotes or apostrophes ? Thanks!



Like


    if (user.department == "IT DEPARTMENTS"



Or



    if (user.department.toLowerCase() == 'IT DEPARTMENTS'





find_real_file.png


Abhinay Erra
Giga Sage

You will also need an onLoad script and put this script in there



  var user = g_form.getReference('requested_for',CallBack);


function CallBack(user){


    if (user.department == "IT DEPARTMENTS" || user.department == "FINANCE DEPARTMENTS" || user.department == "Finance" || user.department == "SUPPLY") {



  g_form.setDisplay('fast_corp', true);


  }


else {


                g_form.setDisplay('fast_corp',false);


          }


}


Added this and it's onLoad client script as well, still no luck.



Why are the UI Policies not working? This is way more complicated than it needs to be, but I appreciate your help as always.