
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 07:25 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 08:50 AM
Hi @Community Alums,
Based on your latest comment, use the below script:
accountAdd: function() {
var arr = [];
var accounts = this.getParameter('sysparm_values');
gs.info('Accounts:'+accounts);// Here I am getting the proper number of sys_ids. If we select 2 accounts we get 2 and so on.
//Querying the customer_account table to get the full list of accounts
var accountsGR = new GlideRecord('customer_account');
accountsGR.query();
//End of customer account query
//Using a counter based on the passed values
var accountCounter = 0;
//End of counter
var accountNames = [];
for (var i = 0; i < accounts.length; i++) {
var gr = new GlideRecord('customer_account');
gr.addQuery('sys_id', accounts[i]);
gr.query();
if (gr.next()) {
accountCounter++;
accountNames.push(''+gr.name);
}
}
gs.info('total Accounts (From customer_account table):' + accountCounter);// Using the accountCounter
gs.info('total Accounts (Passed via variable and script):' + accountsGR.getRowCount());// BUsing the total of records in the customer_account table - accountsGR variable
gs.info('total Account name:' + accountNames.toString());
},
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2024 04:40 AM
Hi @Community Alums,
I'm a little confused - use my latest script which provides what you need.
The 'Company are' and 'count of Company' need to be outside of the for loop.
Here's the script you need as well as a test script you can use in a Background - Script for testing to ensure it provides what you need and expect:
Testing Background Script. Type 'Scripts - Background' into the navigation menu. This is a good place to play and check scripts (In non prod of course)
//BACKGROUND SCRIPT TESTING
//accountAdd: function() {
var arr = [];
//var accounts = this.getParameter('sysparm_values'); // Commented for use in Background Script
var accounts = ['8e6c108413651200042ab3173244b034', '39201da4d7700200e5982cf65e61039f']; //Hard code known sys_id here to check the script is
gs.info('Accounts:'+accounts);// Here I am getting the proper number of sys_ids. If we select 2 accounts we get 2 and so on.
//Querying the customer_account table to get the full list of accounts
var accountsGR = new GlideRecord('customer_account');
accountsGR.query();
//End of customer account query
//Using a counter based on the passed values
var accountCounter = 0;
//End of counter
var accountNames = [];
for (var i = 0; i < accounts.length; i++) {
var gr = new GlideRecord('customer_account');
gr.addQuery('sys_id', accounts[i]);
gr.query();
if (gr.next()) {
accountCounter++;
accountNames.push(''+gr.name);
}
}
gs.info('total Accounts (From customer_account table):' + accountCounter);// Using the accountCounter
gs.info('total Accounts (Passed via variable and script):' + accountsGR.getRowCount());// BUsing the total of records in the customer_account table - accountsGR variable
gs.info('total Account name:' + accountNames.toString());
//},
Here the final script to use within your script include:
accountAdd: function() {
var arr = [];
var accounts = this.getParameter('sysparm_values'); // Commented for use in Background Script
//var accounts = ['8e6c108413651200042ab3173244b034', '39201da4d7700200e5982cf65e61039f']; //Hard code known sys_id here to check the script is
gs.info('Accounts:'+accounts);// Here I am getting the proper number of sys_ids. If we select 2 accounts we get 2 and so on.
//Querying the customer_account table to get the full list of accounts
var accountsGR = new GlideRecord('customer_account');
accountsGR.query();
//End of customer account query
//Using a counter based on the passed values
var accountCounter = 0;
//End of counter
var accountNames = [];
for (var i = 0; i < accounts.length; i++) {
var gr = new GlideRecord('customer_account');
gr.addQuery('sys_id', accounts[i]);
gr.query();
if (gr.next()) {
accountCounter++;
accountNames.push(''+gr.name);
}
}
gs.info('total Accounts (From customer_account table):' + accountCounter);// Using the accountCounter
gs.info('total Accounts (Passed via variable and script):' + accountsGR.getRowCount());// BUsing the total of records in the customer_account table - accountsGR variable
gs.info('total Account name:' + accountNames.toString());
},
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 08:31 AM
Hi @Community Alums ,
Try with while once
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 08:50 AM
Hi @Community Alums,
Based on your latest comment, use the below script:
accountAdd: function() {
var arr = [];
var accounts = this.getParameter('sysparm_values');
gs.info('Accounts:'+accounts);// Here I am getting the proper number of sys_ids. If we select 2 accounts we get 2 and so on.
//Querying the customer_account table to get the full list of accounts
var accountsGR = new GlideRecord('customer_account');
accountsGR.query();
//End of customer account query
//Using a counter based on the passed values
var accountCounter = 0;
//End of counter
var accountNames = [];
for (var i = 0; i < accounts.length; i++) {
var gr = new GlideRecord('customer_account');
gr.addQuery('sys_id', accounts[i]);
gr.query();
if (gr.next()) {
accountCounter++;
accountNames.push(''+gr.name);
}
}
gs.info('total Accounts (From customer_account table):' + accountCounter);// Using the accountCounter
gs.info('total Accounts (Passed via variable and script):' + accountsGR.getRowCount());// BUsing the total of records in the customer_account table - accountsGR variable
gs.info('total Account name:' + accountNames.toString());
},
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2024 04:13 AM
@Robbie I am still getting 1 row count.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2024 04:40 AM
Hi @Community Alums,
I'm a little confused - use my latest script which provides what you need.
The 'Company are' and 'count of Company' need to be outside of the for loop.
Here's the script you need as well as a test script you can use in a Background - Script for testing to ensure it provides what you need and expect:
Testing Background Script. Type 'Scripts - Background' into the navigation menu. This is a good place to play and check scripts (In non prod of course)
//BACKGROUND SCRIPT TESTING
//accountAdd: function() {
var arr = [];
//var accounts = this.getParameter('sysparm_values'); // Commented for use in Background Script
var accounts = ['8e6c108413651200042ab3173244b034', '39201da4d7700200e5982cf65e61039f']; //Hard code known sys_id here to check the script is
gs.info('Accounts:'+accounts);// Here I am getting the proper number of sys_ids. If we select 2 accounts we get 2 and so on.
//Querying the customer_account table to get the full list of accounts
var accountsGR = new GlideRecord('customer_account');
accountsGR.query();
//End of customer account query
//Using a counter based on the passed values
var accountCounter = 0;
//End of counter
var accountNames = [];
for (var i = 0; i < accounts.length; i++) {
var gr = new GlideRecord('customer_account');
gr.addQuery('sys_id', accounts[i]);
gr.query();
if (gr.next()) {
accountCounter++;
accountNames.push(''+gr.name);
}
}
gs.info('total Accounts (From customer_account table):' + accountCounter);// Using the accountCounter
gs.info('total Accounts (Passed via variable and script):' + accountsGR.getRowCount());// BUsing the total of records in the customer_account table - accountsGR variable
gs.info('total Account name:' + accountNames.toString());
//},
Here the final script to use within your script include:
accountAdd: function() {
var arr = [];
var accounts = this.getParameter('sysparm_values'); // Commented for use in Background Script
//var accounts = ['8e6c108413651200042ab3173244b034', '39201da4d7700200e5982cf65e61039f']; //Hard code known sys_id here to check the script is
gs.info('Accounts:'+accounts);// Here I am getting the proper number of sys_ids. If we select 2 accounts we get 2 and so on.
//Querying the customer_account table to get the full list of accounts
var accountsGR = new GlideRecord('customer_account');
accountsGR.query();
//End of customer account query
//Using a counter based on the passed values
var accountCounter = 0;
//End of counter
var accountNames = [];
for (var i = 0; i < accounts.length; i++) {
var gr = new GlideRecord('customer_account');
gr.addQuery('sys_id', accounts[i]);
gr.query();
if (gr.next()) {
accountCounter++;
accountNames.push(''+gr.name);
}
}
gs.info('total Accounts (From customer_account table):' + accountCounter);// Using the accountCounter
gs.info('total Accounts (Passed via variable and script):' + accountsGR.getRowCount());// BUsing the total of records in the customer_account table - accountsGR variable
gs.info('total Account name:' + accountNames.toString());
},
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie