The CreatorCon Call for Content is officially open! Get started here.

Glideaggregate object returning empty values

Tapish Sharma1
Kilo Sage

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

}

}

1 ACCEPTED SOLUTION

Mohith Devatte
Tera Sage
Tera Sage

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

 

 

View solution in original post

7 REPLIES 7

@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

Rahul Talreja
Mega Sage

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();
}

}
Please mark my response correct/helpful as applicable!
Thanks and Regards,
Rahul

Snehal13
Kilo Sage

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.