- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2020 11:20 AM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2020 02:14 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2020 01:53 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2020 02:01 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2020 02:14 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2020 02:20 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2020 02:32 PM
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 🙂