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

Brad Bowman
Kilo Patron
Kilo Patron

You can reference RITM variables in any workflow script simply using the syntax

current.variables.variable_name

Hasan4
Mega Contributor

Thanks for you message Brad but I'm running the workflow on the request table , i don't get any value with your reference variables

Ah, sorry, I just assumed you were referring to a workflow running on the sc_req_item table.  So the script is a bit longer.  The example here is populating the REQ Description field from a variable on the RITM named v_description.

var ritm = new GlideRecord("sc_req_item");
ritm.addQuery("request", current.sys_id);
ritm.query();
while(ritm.next()){
  current.description = ritm.variables.v_description;
}

 

don't work needer... base on this link

https://docs.servicenow.com/bundle/paris-application-development/page/script/server-scripting/concept/c_UsingGlideRecordToQueryTables.html

it seams that we can't directly use the GlidRecord sc_req_item