- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2024 09:21 AM
}}
Can anyone help me with this requirement
Thankyou
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2024 11:53 PM - edited 04-21-2024 12:41 AM
Hi @Hanook ,
I have made changes to the code. Could you please try this code? It is working fine in my PDI. The ‘Watch list’ is a List-type field that expects values in the form of string values separated by commas. For example: ‘Alex Linde, Amy Arquette’ or ‘sysidOne, sysIdTwo’. You need to pass the values to it in the same format. Please use the code below and let me know if it is working or not .
var grm = new GlideRecord('customer_account');
grm.addQuery('name', current.account.name);
grm.query();
gs.log('loop one' + current.account.getDisplayValue());
if (grm.next()) {
var grmh = new GlideRecord('customer_contact');
//var hd = grmh.addQuery('sys_tags.0470568187e58e1075d2a9f40cbb356a','=','0470568187e58e1075d2a9f40cbb356a');
var max = grmh.addQuery('sys_tags.0470568187e58e1075d2a9f40cbb356a', '=', '0470568187e58e1075d2a9f40cbb356a');
max.addCondition('account', '=', current.account);
//grmh.addEncodedQuery('account' + '=' + current.account + '^sys_tags.0470568187e58e1075d2a9f40cbb356a=0470568187e58e1075d2a9f40cbb356a');
grmh.query();
gs.log('loop two' + current.account.name);
// gs.log('Names are one' + grmh.name);
var contactNames = "";
while (grmh.next()) {
contactNames += grmh.name + ','; // Append names with comma
}
// Remove trailing comma (optional)
if (contactNames.length > 0) {
contactNames = contactNames.slice(0, -1);
}
current.watch_list = contactNames;
current.description = contactNames;
current.update();
}
I have tried a similar example in my PDI. Since I wasn’t sure which table you wrote the script for, I have the Glide Incident table and updated the ‘Watchlist’ field. Please take a look at the example and script below
Script -
// This script retrieves contacts associated with a customer account and updates the watchlist and description of an incident record.
// 1. Query customer account with name 'Boxeo USA'
var grm = new GlideRecord('customer_account');
grm.addQuery('name', 'Boxeo USA');
grm.query();
// 2. Check if a customer account record is found
if (grm.next()) {
// 3. Create a GlideRecord object for customer contacts
var grmh = new GlideRecord('customer_contact');
// 4. Define the query to find contacts whose account is 'Boxeo USA' and tag as 'tes'
grmh.addEncodedQuery('sys_tags.ae54d08883b50210e3639496feaad3c9=ae54d08883b50210e3639496feaad3c9^account=8e6c108413651200042ab3173244b034');
grmh.query();
// 5. Initialize a string variable to store contact names
var contactNames = "";
// 6. Loop through each contact record
while (grmh.next()) {
// 7. Append contact name to the string with a comma (optional, adjust comma if needed)
contactNames += grmh.name + ',';
}
// 8. Remove trailing comma from the list of contact names (optional)
if (contactNames.length > 0) {
contactNames = contactNames.slice(0, -1);
}
// 9. Create a GlideRecord object for the incident record (replace '14351daa836d0210e3639496feaad3f6' with the actual incident sys_id)
var gr = new GlideRecord('incident');
gr.get('14351daa836d0210e3639496feaad3f6');
// 10. Update the watchlist and description of the incident record with the list of contact names
gr.watch_list = contactNames;
gr.description = contactNames;
gr.update();
}
Final Outcome -
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-21-2024 01:04 AM
Please give it a try:
var grm = new GlideRecord('customer_account');
grm.addQuery('name', current.account.name);
grm.query();
gs.log('loop one' + current.account.getDisplayValue());
if (grm.next()) {
var grmh = new GlideRecord('customer_contact');
var max = grmh.addQuery('sys_tags.0470568187e58e1075d2a9f40cbb356a', '=', '0470568187e58e1075d2a9f40cbb356a');
max.addCondition('account', '=', current.account);
grmh.query();
gs.info('loop two' + current.account.name);
// Initialize variables to store watch_list and description
var watchList = '';
var description = '';
while (grmh.next()) {
gs.info('Names are two' + grmh.name);
// Append each name to the watchlist and description with a new line
watchList += grmh.name + '\n';
description += grmh.name + '\n';
}
// Set the watch_list and description fields outside the loop
current.watch_list = watchList.trim(); // Remove trailing newline
current.description = description.trim(); // Remove trailing newline
current.update();
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2024 11:53 PM - edited 04-21-2024 12:41 AM
Hi @Hanook ,
I have made changes to the code. Could you please try this code? It is working fine in my PDI. The ‘Watch list’ is a List-type field that expects values in the form of string values separated by commas. For example: ‘Alex Linde, Amy Arquette’ or ‘sysidOne, sysIdTwo’. You need to pass the values to it in the same format. Please use the code below and let me know if it is working or not .
var grm = new GlideRecord('customer_account');
grm.addQuery('name', current.account.name);
grm.query();
gs.log('loop one' + current.account.getDisplayValue());
if (grm.next()) {
var grmh = new GlideRecord('customer_contact');
//var hd = grmh.addQuery('sys_tags.0470568187e58e1075d2a9f40cbb356a','=','0470568187e58e1075d2a9f40cbb356a');
var max = grmh.addQuery('sys_tags.0470568187e58e1075d2a9f40cbb356a', '=', '0470568187e58e1075d2a9f40cbb356a');
max.addCondition('account', '=', current.account);
//grmh.addEncodedQuery('account' + '=' + current.account + '^sys_tags.0470568187e58e1075d2a9f40cbb356a=0470568187e58e1075d2a9f40cbb356a');
grmh.query();
gs.log('loop two' + current.account.name);
// gs.log('Names are one' + grmh.name);
var contactNames = "";
while (grmh.next()) {
contactNames += grmh.name + ','; // Append names with comma
}
// Remove trailing comma (optional)
if (contactNames.length > 0) {
contactNames = contactNames.slice(0, -1);
}
current.watch_list = contactNames;
current.description = contactNames;
current.update();
}
I have tried a similar example in my PDI. Since I wasn’t sure which table you wrote the script for, I have the Glide Incident table and updated the ‘Watchlist’ field. Please take a look at the example and script below
Script -
// This script retrieves contacts associated with a customer account and updates the watchlist and description of an incident record.
// 1. Query customer account with name 'Boxeo USA'
var grm = new GlideRecord('customer_account');
grm.addQuery('name', 'Boxeo USA');
grm.query();
// 2. Check if a customer account record is found
if (grm.next()) {
// 3. Create a GlideRecord object for customer contacts
var grmh = new GlideRecord('customer_contact');
// 4. Define the query to find contacts whose account is 'Boxeo USA' and tag as 'tes'
grmh.addEncodedQuery('sys_tags.ae54d08883b50210e3639496feaad3c9=ae54d08883b50210e3639496feaad3c9^account=8e6c108413651200042ab3173244b034');
grmh.query();
// 5. Initialize a string variable to store contact names
var contactNames = "";
// 6. Loop through each contact record
while (grmh.next()) {
// 7. Append contact name to the string with a comma (optional, adjust comma if needed)
contactNames += grmh.name + ',';
}
// 8. Remove trailing comma from the list of contact names (optional)
if (contactNames.length > 0) {
contactNames = contactNames.slice(0, -1);
}
// 9. Create a GlideRecord object for the incident record (replace '14351daa836d0210e3639496feaad3f6' with the actual incident sys_id)
var gr = new GlideRecord('incident');
gr.get('14351daa836d0210e3639496feaad3f6');
// 10. Update the watchlist and description of the incident record with the list of contact names
gr.watch_list = contactNames;
gr.description = contactNames;
gr.update();
}
Final Outcome -
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-21-2024 01:04 AM
Please give it a try:
var grm = new GlideRecord('customer_account');
grm.addQuery('name', current.account.name);
grm.query();
gs.log('loop one' + current.account.getDisplayValue());
if (grm.next()) {
var grmh = new GlideRecord('customer_contact');
var max = grmh.addQuery('sys_tags.0470568187e58e1075d2a9f40cbb356a', '=', '0470568187e58e1075d2a9f40cbb356a');
max.addCondition('account', '=', current.account);
grmh.query();
gs.info('loop two' + current.account.name);
// Initialize variables to store watch_list and description
var watchList = '';
var description = '';
while (grmh.next()) {
gs.info('Names are two' + grmh.name);
// Append each name to the watchlist and description with a new line
watchList += grmh.name + '\n';
description += grmh.name + '\n';
}
// Set the watch_list and description fields outside the loop
current.watch_list = watchList.trim(); // Remove trailing newline
current.description = description.trim(); // Remove trailing newline
current.update();
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks