Replacing GlideRecord with GlideAggregate to return Object and RowCount
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2023 12:35 AM
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2023 12:56 AM
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.