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

eduque
Giga Expert

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]

9 REPLIES 9

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.


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)


Yeah, an onLoad would get it done. I was trying to do it without one.        


Patrick51
Giga Contributor

I was curious if you ever resolved how to get around this?

TylerTeter
Kilo Guru

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

https://developer.servicenow.com/app.do#!/lp/servicenow_administrator/app_store_learnv2_scripting_ja...

 

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. 

https://www.w3schools.com/tags/ref_urlencode.asp