Identify multiple Child Tasks linked to Parent Task

awentz
Kilo Contributor

I'm trying to disable choices on a choice drop-down (via UI Policy) if there is more than one Active Child record linked to the Parent. It's not working and throwing unexpected results. My guess is I'm not using the aggregate function correctly to identify the Parent-Child Relationship. Both these tables   - Case (parent) and Case Task(child) are tables that extend from the Primary Task table.  

Here's the first code I used (UI Policy):

AutoTemplate.JPG

Unexpected Results:

UnexpectedResults.JPG

It cannot be the 'disableOption' calls because I can get those to work on a simple UI Policy when I use a Condition on the 'When to Apply'.

Any help would be appreciated.

1 ACCEPTED SOLUTION

manikorada
ServiceNow Employee
ServiceNow Employee

Angela,



I doubt if you can use GlideAggregate in Client side thing like UI policy and you can't use 'current' in UI policy


Try something like this:



var count = new GlideRecord('u_ap_case_task');


count.addQuery('active', true);


count.addQuery('parent', g_form.getUniqueValue());


count.query();


var total = 0;


while(count.next())


{


total++;


}



if(total > 1)


{


//do your code here


}


View solution in original post

16 REPLIES 16

Mike Allen
Mega Sage

Your get aggregate should match your add aggregate, so either count.addAggregate('COUNT') or count.getAggregate('COUNT', 'parent.number')



Example



From the developer documentation:


//Number of incidents varies depending on the current state


//of the incident table


var count = new GlideAggregate('incident');


count.addQuery('active', '=','true');


count.addAggregate('COUNT', 'category');


count.query();  


while (count.next()) {


    var category = count.category;


    var categoryCount = count.getAggregate('COUNT', 'category');


    gs.info("There are currently " + categoryCount + " incidents with a category of " + category);


}


Now, other way:



//Number of incidents varies depending on the current state


//of the incident table


var count = new GlideAggregate('incident');


count.addEncodedQuery('active=true');


count.addAggregate('COUNT');


count.query();


var incidents = 0;


if (count.next())


  incidents = count.getAggregate('COUNT');


gs.info(incidents);


I've updated the code based on your first comment...still not working. Thanks for the feedback though.


manikorada
ServiceNow Employee
ServiceNow Employee

Angela,



I doubt if you can use GlideAggregate in Client side thing like UI policy and you can't use 'current' in UI policy


Try something like this:



var count = new GlideRecord('u_ap_case_task');


count.addQuery('active', true);


count.addQuery('parent', g_form.getUniqueValue());


count.query();


var total = 0;


while(count.next())


{


total++;


}



if(total > 1)


{


//do your code here


}