- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2017 05:41 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2017 08:41 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2017 07:58 PM
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2017 08:14 AM
Its running on u_component
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2017 10:27 AM
Did you change line 3 and try ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2017 08:26 AM
yes its not working