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 @Ankur Bawiskar

 

I have to check

if User's location.state == 'AB'

then groupingName = 'Alberto'

else if location.state == 'ON'

then groupingName = 'Ontario'

then what should I add in above code. 

 

Please help me to achieve that. 

 

Regards, 

Nivedita

 

 

 

@niveditakumari 

you want to set groupName as per location.state or as per your existing code where you are checking data for HR profile fields?

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

@Ankur Bawiskar

 

My existing code is existing code which is getting logged in user and in hr profile it is getting some data based on that it is setting grouping name and it is working fine. 

There is another requirement I'm working on that I have to set grouping name based on logged in User.location.state == ' AB' grouing name 'Alberta'. 

 

Regards, 

Nivedita

 

 

 

Regards, 

Nivedita 

 

 

@niveditakumari 

I already shared the logic. You just need to use it as per your requirement wherever you want

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

@niveditakumari 

something like this

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

	if(state == 'AB')
		groupingName = 'Alberto';
	else if(state == 'ON')
		groupingName = 'Ontario';

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