Field Visibility

jared_wentzel
Kilo Contributor

What would be the best way to limit field visibility based on the current users location??

It looks like UI Policies only focus around field values which will not work for this.

1 ACCEPTED SOLUTION

Wow, I am sorry. I should have asked how else I can help you. I will write out an example script for you to use.



Business Rule


g_scratchpad.location= gs.getUser().getLocation();



You access business rules and client scripts by right clicking on the top header bar of whatever table/record you're on.


Client Script


function onLoad() {


        if (g_scratchpad.location == '4b7c157437d0200044e0bfc8bcbe5df5'){


                  g_form.setVisible('<field_name>',false);//Use this if you want there to be an empty spot on the record where the field was


                  //g_form.setDisplay('<field_name>',false);//Use this if you want to have the field's space filled in once hidden


        }


}


Client Scripts - ServiceNow Wiki



That link is for how setVisible works.



This may not be everything that you need, but this will get you in the right direction.



Does this help or do you need more detail? My email is casey.stinnett@crossfuze.com if you want to do a Google + hangout and I can help you out some more.


View solution in original post

24 REPLIES 24

So everyone is sharing the system but we want to filter what incident fields that are being shown when users located outside of the US branch are browsing through already created records, for security reasons, using the company field as the variable. The field should not be shown if the current user is not a member of the US branch and the Customer on the incident is. (As it might contain sensitive data)


jared_wentzel
Kilo Contributor

I hope that makes sense... It's complected to explain.


Oh, it looks okay then. You say it's not working?


Yeah, It won't display the field at all... New record, old record, US member, Non-US member, US Customer, Non-US Customer... It'll only show if I have the admin rule, due to the admin override. How would I change the code to use the actual value, rather than the sys_id of the value? Maybe that's what's tripping it up?


One way to get the sys_id of the location you want is to use a Glide Record (GlideRecord - ServiceNow Wiki)



var sys_id = '';


var   gr = new GlideRecord('cmn_location');


gr.addQuery('name', 'North America');


gr.query();



if(gr.next()){


        sys_id = gr.sys_id;


}



This will load the sys_id of the record in the cmn_location table with the name of North America.