Workflow on "sc_request" with reference to "sc_req_item"

Maki
Tera Expert

Hello all,

i created a workflow on "sc_request" where an event gets started after an "if-statement". 
For that i created two boolean user variables, one at "sc_cat_item" called "u_direktversand_cat" the other at "sc_req_item" called "u_direktversand_item".
A Business Rule set the value on "sc_req_item" to true, if the variable is true in the item at "sc_cat_req" (works fine)

But my conditions always gets "no". In the condition i have to reference the requested item (sc_req_item).

Here is my condition:

answer = ifScript();
function ifScript() {
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request',current.sys_id);
gr.query();
while(gr.next()){
if (gr.variables.u_direktversand_item == 'true'){
return 'yes';
}
return 'no'; 
}
}

Any ideas? Thanks at all

1 ACCEPTED SOLUTION

Ok, then yes the script needs updated. In your script you are looking for the value of a variable on the Item you requested as part of your RITM. 

In your screenshot you are saying that the variables isn't really a variable, its just a field on the sc_req_item table.

 

Try below, this will reference the field on the RITM:

Update it to 

 

while(gr.next()){

gs.log('??? gr.u_direktversand_item Value: ' + gr.u_direktversand_item);

if (gr.u_direktversand_item == 'true'){

 

It also seems redundant to set a field on the Catalog Item and then copy that value over to any corresponding RITMs using that Catalog Item. Unless the field on the sc_req_item table is used for something else, you can dot walk right to that field as well.

 

while(gr.next()){

gs.log('??? gr.u_direktversand_cat Value: ' + gr.cat_item.u_direktversand_cat);

if (gr.cat_item.u_direktversand_cat == 'true'){

 

 

 

If you have multiple RITMs under a given REQ, this could cause issues.

 

 

 

 

 

View solution in original post

12 REPLIES 12

Prateek kumar
Mega Sage

May be change this line to

if (gr.variables.u_direktversand_item == true){


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Tried it before, result still no. 

Throw a gs.log('??? u_direktversand_item Value: ' + gr.variables.u_direktversand_item); after the While but before the If statement and see what (or if) value you are getting.

Ok thats the problem ->

??? u_direktversand_item Value: undefined

Do i have to change the query?