Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Referencing Service Catalog Variables in Workflow

jmiskey
Kilo Sage

We have a Service Catalog to request various Telecom Requests.   I am building a Workflow, based on the Requested Item that is created from the Request.   I am trying to add an IF Action that checks to see if the request was for some special software (in which case, I will then use Create Task to create a task fro the software installation).

So, on the Service Catalog, the variable for the requested item is named u_request_type, and it is a Reference Field to the table which contains the various request selections.   The code for my IF action looks like this:

answer = ifScript();

var requestType = current.variables.u_request_type;

function ifScript() {
      if (requestType == 'Special Software') {
              return 'yes';

      } else {

              return 'no';

      }
}

Needless to say, it doesn't work.   I think it is because the u_request_type is a reference field to another table.

So, how do I get the displayed value for this field?   Do I need to dot-walk, or somehow use GetDisplayName?

Not sure exactly what the code for that needs to look like.

Thanks

1 ACCEPTED SOLUTION

My and Joe, i completely over looked your ifScript function   . Your script looks good to me. Lets try one last thing here , for the if



if(current.variables.u_request_type.service.service_name.indexOf('Avaya Software') > -1){


return 'yes';


}


View solution in original post

29 REPLIES 29

Can you try this background script to see the value stored in the variable?



var gr = new GlideRecord('sc_req_item');


gr.addQuery('number','<RITM #>')


gr.query();


while(gr.next()){


gs.print(gr.variables.u_request_type);


}


I will have to read up on Background Scripts, I have never done them before.



Note that u_request_type is just a Variable in my Service Catalog.   It is not stored in the sc_req_item table.



I got pulled off on an important project, so probably won't be able to pick this up again until morning.


karthik73
Mega Guru

Hi Joe, you can just replace the RITM # in my script (tested) and execute it in the background.


OK. Just getting back to this now.   I ran it and it returned the following:


*** Script: 0b49e1543766ee0047559b7a93990e35


Okie, i wanted to see if you are getting sys id or name.Now , you should be able to get the value (special software... ) by .u_name ( or the field that has the name value in your dependent table).



var gr = new GlideRecord('sc_req_item');


gr.addQuery('number','<RITM #>')


gr.query();


while(gr.next()){


gs.print(gr.variables.u_request_type.u_name);


}



try this