Glide addAggregate not working

aarya
Mega Contributor

Hi All,

I am trying to get number of times a field value(reference field) is   used on my table   and update the count as quantity on the reference table.

details:

u_p2p is reference fields on u_component   - referenced table is u_p2p

here is my business rule:

function onBefore(current, previous) {

    //This function will be automatically called when this rule is processed.

 

    var p2pGr = new GlideAggregate('u_component');

  //gs.addInfoMessage(current.u_p2p.getDisplayValue());

  p2pGr.addQuery(current.u_p2p , current.sys_id)

  p2pGr.addAggregate('COUNT');

  p2pGr.query();

  var sum = 0;

  if(p2pGr.next()){

  sum = p2pGr.getAggregate('COUNT');

  gs.addInfoMessage(sum);

  }

}

i am looking no of times u_p2p is used on u_component table and update quantity on u_p2p table

More info: u_component and u_p2p are related lists on u_cap table - both have common field cap number

in this case u_p2p - 1123 is used 4 times on u_component

so i am looking to update quantity field to 4 on u_p2p table with record number 1123

please help

1 ACCEPTED SOLUTION

can you try below code, if this does not work can you post the screen shot of component form with the u_p2p field on it?


var count = new GlideAggregate('u_component');


count.addQuery('u_p2p',current.u_p2p);


count.addAggregate('COUNT');


count.query();


var incidents = 0;


if (count.next())


    incidents = count.getAggregate('COUNT');


gs.addInfoMessage('Count is '+incidents);


View solution in original post

9 REPLIES 9

nthumma
Giga Guru

    var p2pGr = new GlideAggregate('u_component');


  //gs.addInfoMessage(current.u_p2p.getDisplayValue());


  p2pGr.addQuery(current.u_p2p , current.sys_id)


  p2pGr.addAggregate('COUNT');


  p2pGr.query();


  var sum = 0;


  if(p2pGr.next()){


  sum = p2pGr.getAggregate('COUNT');


  gs.addInfoMessage(sum);


  }


on which table is this BR running?


also, line 3 it should be   p2pGr.addQuery(u_p2p , current.u_p2p)


aarya
Mega Contributor

Its running on u_component


Did you change line 3 and try ?


aarya
Mega Contributor

yes its not working