xl8bot
November 4, 2024, 7:29am
1
Originally asked by Archita Gupta on 05 October 2021 (original question)
How to get the reference value instead of sys id from the catalog task variables in ServiceNow? e.g. in the requested by variable, I am getting sys id instead of user’s name. Code I am using is
catalogTask.request_item = nodeHelper.getReference(“sys_user”, “sys_id”, ${sys_id})?.sys_id
replica.variables = buildVariablesMap(catalogTask.request_item.display_value)
xl8bot
November 4, 2024, 7:29am
2
Answer by Archita Gupta on 07 October 2021
Thanks Francis.
So I adjusted my code and got the name and assigned it to my Requested By variable. Below is the code for someone’s reference.
def all = replica.variables.get("Requested by")
name = user.get("name")
fullName = user.get("name")
replica.variables.("Requested by") = fullName
xl8bot
November 4, 2024, 7:29am
3
Answer by Francis Martens (Exalate) on 05 October 2021
As a side note -
Following code segment looks up a user, dereferences the found value and extracts the sysid (the .sys_id)
catalogTask.request_item = nodeHelper.getReference("sys_user", "sys_id", sys_id)?.sys_id
Assigning it catalogTask.request_item is possible but is semantical incorrect
debug.error("user = ${nodeHelper.getReference("sys_user", "sys_id", sys_id)}")
Comments:
Archita Gupta commented on 06 October 2021
By adding below line, I get error.
debug.error("user = ${nodeHelper.getReference("sys_user", "sys_id", ${sys_id})}")
ERROR:
Caused by: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.$() is applicable for argument types: (Script320$_run_closure1) values:
Francis Martens (Exalate) commented on 06 October 2021
The reason is that ${xxx} is only work in the context of a string.
Please change it to xxx …
Archita Gupta commented on 06 October 2021
Unfortunately, I get this error now:
Caused by: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: sys_id for class
This is the code:
catalogTask.request_item = nodeHelper.getReference(“sys_user”, “sys_id”, sys_id)?.sys_id
debug.error(“user = ${nodeHelper.getReference(“sys_user”, “sys_id”, sys_id)}”)
Francis Martens (Exalate) commented on 06 October 2021
you will have to replace the undefined variable ‘sys_id’ with the variable which contains the sys_id.