I have to get User's location state value.

niveditakumari
Mega Sage

Hi, 

 

I have to get User's location state value. 

I have User's table and from User's table I have to get User's location and then state value in script. 

Below is attached screenshot : 

niveditakumari_0-1696543121111.png

 

In above screenshot I'm getting current logged in User and then I'm querying that in hr profile table and then I'm retrieving entCode and empClass from HR profile table and if that condition satisfy then after that I'm setting groupingName. 

In same way I need to query User's location and get state field value and if state is AB then I need to set groupingName. 

 

Can anyone please help me to achieve that. 

 

Regards, 

Nivedita

 

 

 

23 REPLIES 23

Hi @Mike_R

 

Can you please tell why I'm getting this error. 

Please help me to fix that and help me to achieve that. 

 

Regards, 

Nivedita

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@niveditakumari 

update as this

var user = gs.getUserID();
var hrProfileGR = new GlideRecord('sn_hr_core_profile');
hrProfileGR.addQuery('user', user);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar

 

Thank you for your reply. 

I have to get logged in User's location state field value it means when User's location state is 'AB' then I have to set groupingName is 'Alberto'. 

We don't need to do anything with hr profile table. 

Please find screenshot here we are doing we are getting logged in User and for that logged in User we are getting hr profile and we are getting some field value(entcode, empclass) for that hr profile and if that value matches then we are setting groupingName for that. Same way I have to do with Users location state I have to get logged in User's location state field value it means when User's location state is 'AB' then I have to set groupingName is 'Alberto'. 

 

niveditakumari_0-1696941515641.png

 

Please help me to get for my requirement. 

 

Regards, 

Nivedita

 

 

@niveditakumari 

so what script is written for that?

use this to get logged in user's location and then state, you can use this

var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", gs.getUserID());
gr.query();
if (gr.next()) {
   var loc = gr.location.state;
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar

 

Thank you for your reply. 

I'm writing this code to achieve that if logged in User's location state == 'AB' then we have to set groupingName is 'Alberto'. 

I'll try your code and update you. 

 

Regards, 

Nivedita