2
1
0

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)

    CommentAdd your comment...

    2 answers

    1.  
      2
      1
      0

      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
        CommentAdd your comment...
      1.  
        1
        0
        -1

        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)}")
        1. Archita Gupta

          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:
        2. Francis Martens (Exalate)

          The reason is that ${xxx} is only work in the context of a string.
          Please change it to xxx ...

        3. Archita Gupta

          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)}")

        4. Francis Martens (Exalate)

          you will have to replace the undefined variable 'sys_id' with the variable which contains the sys_id.

        CommentAdd your comment...