- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2023 02:28 AM
Hi Folks,
My problem statement is -
If there is just one contract associated with the account I need to return that contract value , else return null.
I am trying to use Glideaggregate to count the number of records but unable to return the record sysid.
Below is my code snippet -
var ga = new GlideAggregate('ast_contract');
ga.addAggregate('COUNT');
ga.addQuery('account',sysIDofAccount);
ga.query();
if(ga.next()){
var count = ga.getAggregate('COUNT');
if(count==1){
return ga.sys_id; // Gives empty value
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2023 02:50 AM
Hello @Tapish Sharma1 ,
Usually in GlideAggregate API field values cannot be accessed unless there are used in orderBy or sorted.You can only get count of the records with above script
try below script to get the sys_id
var ga = new GlideAggregate('ast_contract');
ga.orderBy('sys_id');
ga.addAggregate('COUNT');
ga.addQuery('account',sysIDofAccount);
ga.query();
if(ga.next()){
var count = ga.getAggregate('COUNT');
if(count==1){
return ga.sys_id; // Gives empty value
}
}
Hope this helps
Mark my answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2023 02:58 AM
@Tapish Sharma1 Yes you can use the get row count but in that case you can use glide record which would give you access to the fields with out order by .
Hope this helps
Mark my answer correct if this helps you
THanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2023 03:18 AM
Hi @Tapish Sharma1 ,
Try with:
var ga = new GlideAggregate('ast_contract');
ga.addQuery('account',sysIDofAccount);
ga.addAggregate('COUNT','sys_id');
ga.query();
var count = 0;
if(ga.next()){
var count = ga.getAggregate('COUNT','sys_id');
if(count==1){
return ga.sys_id.toString();
}
}
Thanks and Regards,
Rahul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2023 03:42 AM - edited 08-11-2023 06:44 AM
I think GlideAggregate wont have sys id since it is a diff API for aggregation purpose and not on record level like GlideRecord.
2 queries needed.