get reference value of a glideAggregate

francesco_ugolo
Kilo Guru

Hi, I'm trying to get the value of a reference field from the following query but also using getValue() and getDisplayValue() i receive an undefined or null value; how can I get it out?

Here the script:

"

var req_all_sum = new GlideAggregate('requested_allocation');

req_all_sum.addAggregate('SUM', 'fte');

req_all_sum.addAggregate('SUM', 'requested_hours');

req_all_sum.addQuery('resource_plan.state','3');

req_all_sum.groupBy('resource_plan.user_resource');

req_all_sum.groupBy('resource_plan.task');

req_all_sum.groupBy('u_year_month');

req_all_sum.setQueryReferences(true);

req_all_sum.query();

while (req_all_sum.next()) {

        gs.log("User " + " FTE " +req_all_sum.getAggregate('SUM', 'fte')+" hours "+ req_all_sum.getAggregate('SUM', 'requested_hours') +" Project " + req_all_sum.resource_plan);

        gs.log("user: " + req_all_sum.resource_plan.user_resource.getDisplayValue()); // nothing

        gs.log("user: " + req_all_sum.resource_plan.user_resource.getValue()); // undefined

        gs.log(req_all_sum.u_year_month.getDisplayValue()); //here I see the value

}

"

1 ACCEPTED SOLUTION

I got the values in this way



req_all_sum.getValue("resource_plan.user_resource");


req_all_sum.getValue("resource_plan.task");


View solution in original post

4 REPLIES 4

SanjivMeher
Kilo Patron
Kilo Patron

What do you get if you do gs.log as shown below



        gs.log("user: " + req_all_sum.resource_plan.getDisplayValue()); // nothing


        gs.log("user: " + req_all_sum.resource_plan.getValue()); // undefined


        gs.log("user: " + req_all_sum.resource_plan.getDisplayValue()); // nothing


        gs.log("user: " + req_all_sum.resource_plan.getValue()); // undefined


        gs.log("user: " + req_all_sum.resource_plan.user_resource.getDisplayValue()); // nothing


        gs.log("user: " + req_all_sum.resource_plan.user_resource.getValue()); // undefined



Please mark this response as correct or helpful if it assisted you with your question.

I get the same result.


Chuck Tomasi
Tera Patron

req_all_sum is your aggregate. You have two of them, fte and requested_hours. Those are the two things you can get from req_all_sum. You cannot dot-walk to other objects in the GlideRecord because it's not a GlideRecord, it's a GlideAggregate (doing completely different stuff at the database level.)



See the examples here for more insight;



http://wiki.servicenow.com/index.php?title=GlideAggregate#gsc.tab=0


I got the values in this way



req_all_sum.getValue("resource_plan.user_resource");


req_all_sum.getValue("resource_plan.task");