Get the value of a requested item variable on workflows

Hasan4
Mega Contributor

Hello,

I'm trying to set a workflow to get the value of a requested item variable.

I tried to get these information using the GlideRecord sc_item_option_mtom
but the request sys_id never match the the request_item .

Do you have an idea why ?
Thanks in advance,

1 ACCEPTED SOLUTION

I am using this exact script in a Run Script activity on the workflow that runs on the sc_request table when I submit a Catalog Item.  The result is my REQ Description is populated with the string variable that I am populating on the request form.  Without this Run Script activity, this doesn't happen.  You can add some workflow.info lines to find out why it's not working in your case.  Add one right at the beginning to confirm the script is running, then inside the while loop to confirm that an RITM was found.  This log inside the while loop should also contain the variable you're trying to get the value of, so in my example I would add these logs to see what the script is doing

workflow.info('GR script running');
var ritm = new GlideRecord("sc_req_item");
ritm.addQuery("request", current.sys_id);
ritm.query();
while(ritm.next()){
  workflow.info('RITM found: ' + ritm.number + ' Description variable contains: ' + ritm.variables.v_description);
  current.description = ritm.variables.v_description;
}

After I submit a new Catalog Item, I can click the Workflow Context link on the Request to view the log tab.  In my example, there could be more than one RITM for this REQ, so the resulting REQ Description will be that of the last record returned.  You also need to ensure the variable name is correct, of course, then your variable type will determine the value that is stored.  If this doesn't lead you to the resolution of your issue, post your script and let me know the variable type you are trying to get the value of, and what you want to do with it.

View solution in original post

7 REPLIES 7

I am using this exact script in a Run Script activity on the workflow that runs on the sc_request table when I submit a Catalog Item.  The result is my REQ Description is populated with the string variable that I am populating on the request form.  Without this Run Script activity, this doesn't happen.  You can add some workflow.info lines to find out why it's not working in your case.  Add one right at the beginning to confirm the script is running, then inside the while loop to confirm that an RITM was found.  This log inside the while loop should also contain the variable you're trying to get the value of, so in my example I would add these logs to see what the script is doing

workflow.info('GR script running');
var ritm = new GlideRecord("sc_req_item");
ritm.addQuery("request", current.sys_id);
ritm.query();
while(ritm.next()){
  workflow.info('RITM found: ' + ritm.number + ' Description variable contains: ' + ritm.variables.v_description);
  current.description = ritm.variables.v_description;
}

After I submit a new Catalog Item, I can click the Workflow Context link on the Request to view the log tab.  In my example, there could be more than one RITM for this REQ, so the resulting REQ Description will be that of the last record returned.  You also need to ensure the variable name is correct, of course, then your variable type will determine the value that is stored.  If this doesn't lead you to the resolution of your issue, post your script and let me know the variable type you are trying to get the value of, and what you want to do with it.

Mybad, I was trying to get a reference value,  I do have all needed information now...

Thanks for your assistance Brad.

You are welcome.  Glad to hear your issue is resolved!