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

Oops, I know why. Here department is a reference field on user table use the sys_id's of departments



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


function CallBack(user){


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



  g_form.setDisplay('fast_corp', true);


  }


else {


                g_form.setDisplay('fast_corp',false);


          }


}


Abhinay is on to something Alexander, and I'd like to build on his advice somewhat.



My suggestion is to add a column to the department to indicate that the department is a "fast_corp".


Although I don't know enough of your use case to say what type of column to use,   I'll assume that a "yes/no" field is sufficient.


The the script to perform the setDisplay would just check the value of user.department.u_fast_corp == 'yes'.



Why would I do this?   Because this looks like a situation where additional departments may be added in the future, or some departments may be dropped off.   In that kind of situation, you won't need to edit the script, but would just update the department record's "fast_corp" field.



Just my .02 worth.


Great idea, I might use this in the future for something else. This specific application is actually being retired, so we will not have to add any more departments.


This is odd, if I click in the checkbox, it disappears, regardless of whether or not the user matches one of the departments.


post the screenshots. Make sue you are using correct sys_id's of the department.