Replacing GlideRecord with GlideAggregate to return Object and RowCount

Rajshri1
Tera Contributor

This is the Existing code which returns an Object.

 

_getChildLCAObject: function(parentLCA) {
        var grParent;
        if (typeof parentLCA == 'string') {
            grParent = new GlideRecord('u_pmg_lca');
            grParent.get(parentLCA);
        } else
            grParent = parentLCA;

        var grChildLCA = new GlideRecord('u_pmg_lca');
        grChildLCA.initialize();
        grChildLCA.addQuery('u_parent_lca_record', grParent.getValue('sys_id'));
        grChildLCA.addQuery('u_child_lca_status', "");
        if (grParent.getValue('u_source') != 'direct_hire')
            grChildLCA.addQuery('u_approval_result', 'Approved').addOrCondition('u_approval_result', 'Updates Approved');
        grChildLCA.orderBy('u_number');
        grChildLCA.query();
        return grChildLCA;
    },
 
 
We have replaced above code with the following code where need to return Count As well as the Object, but it is not working as expected. 
Could you please suggest if we are missing something.
 
_getChildLCAObject: function(parentLCA) {
        var grParent;
        if (typeof parentLCA == 'string') {
            grParent = new GlideRecord('u_pmg_lca');
            grParent.get(parentLCA);
        } else
            grParent = parentLCA;

        var grChildLCA = new GlideAggregate('u_pmg_lca');
        //var grChildLCA = new GlideRecord('u_pmg_lca');
        grChildLCA.initialize();
        grChildLCA.addQuery('u_parent_lca_record', grParent.getValue('sys_id'));
        grChildLCA.addQuery('u_child_lca_status'"");
        if (grParent.getValue('u_source') != 'direct_hire')
            grChildLCA.addQuery('u_approval_result''Approved').addOrCondition('u_approval_result''Updates Approved');
        grChildLCA.orderBy('u_number');
        grChildLCA.addAggregate('COUNT','u_number');
        grChildLCA.query();
        return grChildLCA;
1 REPLY 1

Kalyani Jangam1
Mega Sage
Mega Sage

Hi @Rajshri1 

 initialize() and insert() are methods of the GlideRecord class, we can not use in GlideAggregate. Once record insert by using GlideRecord then we can count by using GlideAggregate.

 

Please check and Mark Helpful and Correct if it really helps you.