I have to get User's location state value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2023 03:06 PM
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 :
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2023 05:29 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2023 05:31 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2023 05:41 AM
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'.
Please help me to get for my requirement.
Regards,
Nivedita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2023 05:54 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2023 06:01 AM
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