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

Your if then statement contains a single "&".



Try this:



var id1 = <the first sys_id>


var id2 = <the second one>


if (!((curloc != id1) && (cusloc == id2))) {


      answer = true;


}


else {


      answer = false;


}


Although I don't recommend hardcoding sys_ids into your scripts if you can avoid it. You would be better off searching for the company record by name and then getting its sys_id.


By the way, this has been a SUPER big help for me. http://www.servicenowguru.com/showcase/sncguru-search-provider/



When you install this in Chrome, you can choose a key word to use so that when you type that into your omnibox (I use the word 'snow') and then push tab, you can then type in your search and Google will search all of the ServiceNow Wiki, ServiceNow Guru, and these forums. All three of those are going to be your biggest helps in learning ServiceNow.



I would also suggest JavaScript | Codecademy for a really good tutorial on learning basic JavaScript.


prdelong
Kilo Guru

Is there anything from preventing you from using an ACL with filters? You can also accomplish it an ACL script, but this way you don't have to worry about a BR and a client script.


neetusingh
Giga Guru

I believe that the best way to limit the visibility of field can be ACL..