How to get value of a field in glideaggregate?

Ankita Kolhe
Tera Contributor

Hi Community,

How to get value of a field in glideaggregate?

 

code:-

var cd=new GlideAggregate('choice_definitions');
cd.addQuery('field_name=Membership Status^choice_valueIN'+memStatus);
cd.addAggregate('MIN', 'order');
cd.setGroup(false);
cd.query();


while(cd.next()){
var test=cd.choice_value;

gs.info('Most recent Incident Created Date = ' + cd.getAggregate('MIN', 'order'));
gs.info('test:  '+test);


}

 

output- 

Most recent Incident Created Date = 420
test:

 

Could someone pls help on this?

 

Thanks in advance! 

6 REPLIES 6

Maddysunil
Kilo Sage

@Ankita Kolhe 

you're trying to access the choice_value field directly from the GlideAggregate object, but GlideAggregate doesn't provide direct access to field values like that. Instead, you need to use the getValue() method to retrieve the value of a field. Please try with below code:

 

var cd = new GlideAggregate('choice_definitions');
cd.addQuery('field_name=Membership Status^choice_valueIN' + memStatus);
cd.addAggregate('MIN', 'order');
cd.setGroup(false);
cd.query();

while (cd.next()) {
    var test = cd.getValue('choice_value');
    gs.info('Most recent Incident Created Date = ' + cd.getAggregate('MIN', 'order'));
    gs.info('test: ' + test);
}

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

 

 

Hello @Maddysunil ,

 

I had tried with getValue() also, but unfortunately it was not working.

 

Thanks

@Ankita Kolhe 

Are you sure 'choice_value' field present on the table choice_definitions table also validate if value is present in the field.Please validate once

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

Yes, the field and value both are present in choice_definition table.