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

Undefined could mean a few things. Does this variable actually exist on the Catalog item referenced in the RITM? Does the variable have a default prior to you modifying it with the Business Rule? If you don't have a default value, its possible that your BR isn't doing what you think it is.

In the Requested Item -> Show XML, i can find my variable

<u_direktversand_item>true</u_direktversand_item>

This is my Business Rule :

When to run: insert

find_real_file.png

And also in the record history of the requested item i can see the variable

find_real_file.png

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.

 

 

 

 

 

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.

Im new in Snow, this is my first Workflow 🙂 

But yes, i just need the CheckBox in the sc_cat_item table, but i thought i need it also in sc_req_item table to reference. I will take your example and delete the column in sc_req_item. 

 

still took the "no" way, but variable was -> ??? gr.u_direktversand_cat Value: true

I changed the code to: 

if (gr.cat_item.u_direktversand_cat == true)

and now the workflow takes the "yes" was. Thanks a lot.

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

Yes i know, but i wanted the workflow to start first 🙂