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

I guess if (current.variables.u_request_type.service.service_name) will return 'true' whenever there is a value in that variable, did you get a chance to test the negative (no) functionality?


I spoke too soon.   You are correct.   I picked some other Service, and this expression incorrectly evaluated to 'yes'.   So it is not working correctly.


Before, everything was evaluating to 'no'.   Now everything is evaluating to 'yes'.



Back to the drawing board...


I hope your workflow is running on the req_item table. Can you please add logging in workflow to see , what value you are getting in the requestType variable you are creating


Yes, it is running on the sc_req_item table.



You will have to forgive me, I am a bit new to Java programming.   What is the best way of adding logging?


You can try with the gs.log



gs.log('variable value'+requestType);


gs.log('variable value from task'+current.variables.u_request_type.service.service_name);



add the above 2 lines to your script and then see what values you see in the system logs against these log statements.



There is also workflow specific logging, which i haven't used so far.