gs.getUser().getUserByID() in a URL sysparm

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 08:47 AM
Anybody know if gs.getUser().getUserByID works in a URL sysparm for a new record form?
I have:
sysparm_query=caller_id=javascripts:gs.getUser().getUserByID(userid)
But it's not returning properly. Any ideas?
[edit: corrected url]

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 09:30 AM
I'm not trying to get the my sys_id into the field. I'm trying to get the user_id of whatever I put into the field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 09:31 AM
Hi Earl,
another suggestion, I don't know your requirement, looking at the url it seems you want a different user there; so, is this something you can do with an onDisplay bussiness rule + onLoad client script?, or just an onLoad client script?, I guess if you do it that way you would only have to work on when it should execute (ie: linking the onLoad client script that would get the userId to a certain view called by your url)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 09:33 AM
Yeah, an onLoad would get it done. I was trying to do it without one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2018 01:56 PM
I was curious if you ever resolved how to get around this?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2018 02:56 PM
Looks like this format should work
https://<instancename>.service-now.com/nav_to.do?uri=/incident.do%3Fsysparm_query%3Dcaller_id%253Djavascript:gs.getUserID()
Since caller_id is a reference field, you need to have something that will return a sys_id to dynamically work.
The documentation isn't the most complete, there are a couple undocumented user object methods, but these are the most complete there are. Both gs.getUser() and g_user are referred to as user objects, but g_user is client side, and gs.getUser() (and other gs methods) are server side.
https://www.servicenowguru.com/scripting/user-object-cheat-sheet/
https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_ScopedGlideSystemGetUserID
Since it may be part of your issue here, and for a deeper understanding, some URL characters can't be interpreted directly by the browser, so ServiceNow encodes them in the hexadecimal ASCII standard. For example, = is %3D. Then it looks like to make it work, you have to doubly encode the % symbol (%25) to make a javascript call work.