How to hide one field based on the user's Location?

Ramu6
Tera Contributor

Hi All,

I  have a requirement that basically i have one record producer, in that i have one variable set, in that , three fields, "subject person, leave type and period", , so my requirement was that the field 'leave type' was only visible , when the users with location (WA or SA),

 

So please help me to achieve this

 

Thanks

Ramu

10 REPLIES 10

RAMANA MURTHY G
Mega Sage
Mega Sage

Hello @Ramu6 ,

Give me some clarity, in your question "when the users with location (WA or SA)", here users means the logged user or is there any requester field?

 

Please mark my answer helpful  & correct if it helps you
Thank you

G Ramana Murthy
ServiceNow Developer

Hi Ramana,

Thanks for the response

Actually there is one 'Subject person", its reference filed to user table only, so based on this we need to hide the other field

 

Thanks

Ramu

Hello you can write a catalog onchange client script on variable subject person

 

Client Script:

var ga = new GlideAjax('demoAjax');//Script Include name
 ga.addParam('sysparm_name','getLocation'); // /Script Include function
 ga.addParam('sysparm_user',newValue); // send sysid of subject person
 ga.getXML(getInfo);
 function getInfo(response) {
 var info = response.responseXML.documentElement.getAttribute('answer');
if (info == 'WA' || info == 'SA' )
 g_form.setVisible('fieldname',false);
 }
else
{
g_form.setVisible('fieldname',true);
}
 
Script include:
    getLocation: function() {
        var userID = this.getParameter('sysparm_user');// sysid of sub person from client script
        var returnID = '';
        var user = new GlideRecord('sys_user');
        user.addQuery('sys_id', userID);
        user.query();
        if (user.next()) {
            return user.location.name; // return User's location name
        }
    },
Regards
Harish

Ramu6
Tera Contributor

Hi @Harish KM 

thanks for the response and sorry for the delaying

 

I have tried this code but it always go to else part only , if we select any user it hides the field