I want to put an if condition with glide record script on the workflow that creates GTASKs (child tasks) of a GREQ when complexity is medium or complex checking the number of GTASKs if it is 0 or not.

utkarsha_s
Kilo Expert

Hi Guys,

I want to put an if condition with glide record script on the workflow that creates GTASKs (child tasks) of a GREQ when complexity is medium or complex checking the number of GTASKs if it is 0 or not. I want to query the u_incident_task table to through a glide record to check the number of GTASKs on the parent GREQ form and if it is 0 then go ahead to create the child in the workflow else end the workflow.

I need the script to do this, please let me know what would be the exact script.

find_real_file.png

Thanks,

Utkarsha Saxena

1 ACCEPTED SOLUTION

var gtsks = new GlideRecord('gtask table');


gtsks.addQuery('parent',current.sys_id);   //this assumes that your GTasks are linked to your GREQ's via the parent field


gtsks.query();



if (gtsks.next()){


  answer = true;


} else {


  answer = false;
}





Embed that code in an If statement activity and you should be ok.


View solution in original post

6 REPLIES 6

More importantly... do you understand how/why it works?


Yes Robert I do understand how this one is working, actually I had written something similar but it didn't work.. also in your script I had to twist the true and false section and then it worked.



var inc = new GlideRecord('u_incident_task');
inc.addActiveQuery();
inc.addQuery('parent.number','current.sys_id');
inc.addAggregate('','parent.number');
inc.query();
var gtasks = 0;
if(inc.next())
{
gtasks = inc.getAggregate('COUNT');
}
if(gtasks > 3)
{
          return 0;
}



This wasn't working though yours worked fine.



Thanks again!


Utkarsha