If condition in workflow for approval

keerthana19
Tera Contributor

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)

find_real_file.png

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

 find_real_file.png

If level matches with division check “Name’ field for Central data. (Name field is text field)

Here is the script I was working

 find_real_file.png

You can refer to the word document attached

 

 

7 REPLIES 7

find_real_file.png

I think there is an error is line 19 toString is not highlighted

and line 30 getRefRecord also

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.

Regards,
Muhammad

rajneeshbaranwa
Giga Guru
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.