Reference Catalog Item Variables from workflow

ankitamin
Kilo Contributor

Hi I am trying to create a new branch on my service catalog request workflow to differentiate between Service Requests and Purchase requests to get rid of the "automatically approved <$1000" step on a service request.

I created a variable set that I am applying to all of my service request catalog items that contains a hidden variable (Yes/No) called service_req_id and I am setting the default value to Yes (doing the opposite for purchase requests). Then I am creating an If condition workflow activity to check if this variable is Yes or No and return the correct answer to branch my workflow.

Unfortunately I am getting an "undefined" response when trying to get the value of the service_req_id variable. From what I understand it is because that variable is on the sc_req_item table and the workflow is running on the sc_request table. Is there any way to reference my variable on the sc_req_item table or is there a better approach for what I am trying to accomplish?

Here is the code that I am using:

//Checks if the requested item is a service request or not to branch off the service catalog workflow between service requests and purchase requests

var request = new GlideRecord('sc_request');

answer = check();

function check() {
//Check if the requested item is a service request

//service_req_id is a hidden variable on the catalog item that is set to Yes for service request items and No for purchase requests

if (current.variables.service_req_id != "undefined" && current.service_req_id == 'Yes') {

return 'yes';

}

return 'no';
}

1 ACCEPTED SOLUTION

I'm not sure I understand your request, but this might help:



Catalog items define a form available in your catalog


When users complete the catalog form and submit it, two records are generated: Request (the cart) and Requested item (the specific form they completed)


Variables live on the requested item


Upon submission, the first workflow to run in on the Request. If you want to reference variables on the Requested Items under the request, you must use a GlideRecord query to find all requested items where the request is the current record and then check their variables:


var r = new GlideRecord('sc_req_item');


r.addQuery('request',current.sys_id);


r.query();


while(r.next()){


if(r.variables.variable_name....)....


}


After the Request workflow completes and is approved, the requested item workflow runs. From this workflow, it is simple to reference the variables: current.variables.variable_name.



Hope that helps


View solution in original post

8 REPLIES 8

kristenankeny
Tera Guru

Use gliderecord to look up all the items under your sc_request and determine their setting. Is it possible for people to submit a combination of service and purchase requests? If so, you'll probably want to count the numbers of each and determine your workflow route from there.


Is there any way to capture the variable value from the catalog item form on the catalog workflow? The value that is set on the catalog item is not mapped to anything on the actual request because I cannot figure out how to get the value of it before moving onto the catalog item workflow.


I'm not sure I understand your request, but this might help:



Catalog items define a form available in your catalog


When users complete the catalog form and submit it, two records are generated: Request (the cart) and Requested item (the specific form they completed)


Variables live on the requested item


Upon submission, the first workflow to run in on the Request. If you want to reference variables on the Requested Items under the request, you must use a GlideRecord query to find all requested items where the request is the current record and then check their variables:


var r = new GlideRecord('sc_req_item');


r.addQuery('request',current.sys_id);


r.query();


while(r.next()){


if(r.variables.variable_name....)....


}


After the Request workflow completes and is approved, the requested item workflow runs. From this workflow, it is simple to reference the variables: current.variables.variable_name.



Hope that helps


Thanks that definitely does help! I am going to try that out and report back.