If condition in workflow for approval
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2020 07:00 AM
I have to create an additional approval if level is division and name is Central data.
In my catalog item I have a variable called ‘Type’ referenced to ‘alm_hardware’ table I have to query the record selected in Type and check if level is division or not(level has 5 choices)
If level is not division, then it should check the record selected in parentID for level is division or not this process should repeat until level is division
ParentID is referenced to ‘alm_hardware’ table
If level matches with division check “Name’ field for Central data. (Name field is text field)
Here is the script I was working
You can refer to the word document attached
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2020 09:42 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2020 10:14 AM
No that is fine. Please replace return true -> return 'yes' and return false -> return 'no';
Also, try placing a few logs [gs.log] to understand the code flow and where it's breaking.
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2020 08:21 AM
answer = ifScript();
function ifScript()
var gr =new GlideRecord("alm_hardware");
gr.addEncodedQuery("sys_id"+current.variables.vType.toString());
gr.query();
if(gr.next()){
if(gr.getValue('u_level') == 'division'){
return "yes";
} else{
var parent = gr.parent.getRefRecord();
var parentIsDivision = checkIFParentIsDivision(parent);
while (parentIsDivision == "false" && parent.isValidRecord())
{
parent = parent.parent.getRefRecord();
parentIsDivision = checkIFParentIsDivision(parent);
}
if (parentIsDivision == "true")
{
var name = parent.name;
if (name == "Central Data"
{
////Do your stuff here
}
}
}
}
function checkIFParentIsDivision(record)
{
var gr =new GlideRecord("alm_hardware");
gr.addEncodedQuery("sys_id=" + record);
gr.query();
if(gr.next()){
if(gr.getValue('u_level') == 'division'){
return "true";
} else{
return "false"
}
}
You may try using above script. This will check parent record until it finds any record with Division level.