- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 12:34 AM
Hi Team,
Below is my Script Include:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 01:09 AM
Hi @Community Alums ,
I tried similar code in my PDI, which I shared with you, and it is working fine for me. Please have a look at the code and screenshots
Code -
var accountList = [];
var rel = new GlideRecord('sn_customerservice_contact_relationship');
rel.addQuery('sys_id','76d50803910b3410f87731ea9e8493d0');
rel.query();
if (rel.next()) {
var acc = new GlideRecord('customer_account');
acc.addEncodedQuery('nameSTARTSWITHBoxeo');
acc.query();
gs.info('Total Account Path Cos:' + acc.getRowCount());
while (acc.next()) {
var account = {}; // Create a new object for each record
account.name = acc.name.getDisplayValue();
account.sys_id = acc.sys_id.toString();
accountList.push(account); // Add the object to the array
}
//gs.info('Name of All accounts:' + accountList[0].name); // This will print the first record's name (optional)
gs.print( JSON.stringify(accountList));
}
If my reply helped with your issue please mark helpful 👍 and correct ✔️ if your issue is resolved.
By doing so you help other community members find resolved questions which may relate to an issue they're having
Thanks,
Astik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 01:39 AM
Hi @Community Alums ,
try :
getAccountList: function() {
var accountList = [];
var rel = new GlideRecord('sn_customerservice_contact_relationship');
rel.addQuery('sys_id', this.getParameter('sysparm_sys_id'));
rel.query();
if (rel.next()) {
var acc = new GlideRecord('customer_account');
acc.addEncodedQuery('account_parent.account_pathSTARTSWITH' + rel.company.account_parent.account_path.getDisplayValue());
acc.query();
gs.info('Total Account Path Count:' + acc.getRowCount());
while (acc.next()) {
var account = {};
account.name = acc.name.getDisplayValue();
account.sys_id = acc.sys_id.toString();
gs.info('Name of Account: ' + account.name);
accountList.push(account);
}
}
return JSON.stringify(accountList);
},
type: 'GetAccountsAjax'
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 12:38 AM
Hi @Community Alums ,
Can you try below code -
getAccountList: function() {
var accountList = [];
var rel = new GlideRecord('sn_customerservice_contact_relationship');
rel.addQuery('sys_id', this.getParameter('sysparm_sys_id'));
rel.query();
if (rel.next()) {
var acc = new GlideRecord('customer_account');
acc.addEncodedQuery('account_parent.account_pathSTARTSWITH' + rel.company.account_parent.account_path.getDisplayValue());
acc.query();
gs.info('Total Account Path Cos:' + acc.getRowCount());
while (acc.next()) {
var account = {}; // Create a new object for each account
account.name = acc.name.getDisplayValue();
account.sys_id = acc.sys_id.toString();
accountList.push(account);
}
}
return JSON.stringify(accountList);
},
type: 'GetAccountsAjax'
});
If my reply helped with your issue please mark helpful 👍 and correct ✔️ if your issue is resolved.
By doing so you help other community members find resolved questions which may relate to an issue they're having
Thanks,
Astik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 12:40 AM
@Astik Thombare I am already doing this if you recheck my code , I am passing the value to JSON so there is no difference with what you have sent.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 12:43 AM
Hi @Community Alums
You need to push accountList.push(account); statement within while loop.
Since the above statement is kept outside while, its being executed only once, when the while loop ends executing.
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 12:45 AM
@Astik Thombare Now its giving me 3 records but all are same not different as it should should show 3 different records