How to push GlideRecord query to an array
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2023 07:28 AM
How to push GlideRecord query to an array in a Before Query BR
Please find the code below:
I want to push the GlideRecord query to an array.
Note : I have written this code on a Before Query BR
var answer = [];
var grRole = new GlideAggregate('x_amspi_smdrs_app_role_matrix');
grRole.groupBy('site');
grRole.query();
while (grRole.next()) {
var grInp = new GlideRecord('x_amspi_smdrs_app_input_ola');
grInp.addQuery('site', grRole.site);
grInp.addQuery('role', 'DM');
grInp.query();
while (grInp.next()) {
gs.info('check code');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2023 08:14 AM - edited 04-10-2023 08:16 AM
You appear to be missing the syntax to push the query data into the array you declared with var answer = [] and then what to do with the contents of the array
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2023 08:16 AM
I know @Ian Mildon, but I am not sure how to do it. I want to push both role and site into an array.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2023 08:21 AM
Here is a quick BR to gather all "assigned_to" values for a record, add it to an array and then take the contents of the array and populate another field with all the contents.
(function executeRule(current, previous /*null when async*/ ) {
var taskAssign = []; //create array
var getAssigned = new GlideRecord('sc_task');
getAssigned.addQuery('request_item', current.sys_id);
getAssigned.query();
while (getAssigned.next()) {
taskAssign.push(getAssigned.getDisplayValue('assigned_to'));
}
current.u_sctask_assigned_all = taskAssign.join(','); //push array contents to list field
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2023 10:13 AM
https://www.codecademy.com/catalog/language/javascript
and start your journey to learning javascript.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2023 10:31 AM
Did a little reworking of your script. Can't say if this actually works as I don't have the same tables/values as you; but it should give you some ideas on what to try.
getRoleAndSite();
function getRoleAndSite() {
var grRole = new GlideAggregate('x_amspi_smdrs_app_role_matrix');
grRole.groupBy('site');
grRole.query();
var answer = [];
while (grRole.next()) {
answer.push(grRole.site.toString());
}
var arrayUtil = new ArrayUtil();
var getSite = arrayUtil.unique(answer)
var grInp = new GlideRecord('x_amspi_smdrs_app_input_ola');
grInp.addQuery('site', 'IN', getSite);
grInp.addQuery('role', 'DM');
grInp.query();
while (grInp.next()) {
gs.info('check code');
}
}