- 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 02:33 PM
Glad to hear. Please mark the comment if correct if all is cleared up.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2020 02:21 AM
If you have multiple RITMs under a given REQ, this could cause issues.
Here is my final solution with another if-statement that checks if any item is false. In this case the no condition is selected.
answer = ifScript();
function ifScript() {
var gr = new GlideRecord('sc_req_item');
var direkt = 'yes';
gr.addQuery('request',current.sys_id);
gr.query();
while(gr.next()){
if (gr.cat_item.u_direktversand == true){
if (direkt == 'yes'){
direkt = 'yes';
}
else direkt = 'no';
}
else direkt = 'no';
}
if (direkt == 'yes'){
return 'yes';
}
return 'no';
}
If there is a better solution let me know 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2020 01:56 PM
Try this
gr.addQuery('sc_request',current.sys_id);