- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2024 10:35 AM
HI Team,
I have created a custom action in flow designer as below:
Line no 13 'u_account' is a list collector field.
Line no 14 I am getting list comma separated Names of accounts
Line no 17 is printing 18 account names which is correct.
Line no 20 is where the issue is.
'company' is a reference field and its showing empty values on insertion.
At line no 24 I am creating records which is creating 18 records in contact Relationship table which is correct
but Company field whose backend name is account is showing as Blank.
Kindly help in resolving the issue
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2024 03:26 PM - edited 06-08-2024 03:27 PM
Hi @Community Alums ,
The issue might be in how you are setting the account value (sp[i]) in the company reference field. Reference fields expect a sys_id of the referenced record, not a display value or name.
Please find the updated code-
var sys_id = inputs.sysid;
var ga = new GlideRecord('sn_customerservice_bulkupdatecontactrelationship');
ga.addQuery('sys_id', sys_id);
ga.query();
if (ga.next()) {
var ac = ga.getValue('u_accounts');
var sp = ac.split(',');
for (var i = 0; i < sp.length; i++) {
// Query the sys_user table to get the sys_id of the account name
var userGR = new GlideRecord('sys_user'); // Use the appropriate table name
userGR.addQuery('name', sp[i].trim()); // Assuming 'name' holds the account names
userGR.query();
if (userGR.next()) {
var accountSysId = userGR.sys_id;
//create new record in sn_customerservice_contact_relationship
var gr = new GlideRecord('sn_customerservice_contact_relationship');
gr.initialize();
gr.company = accountSysId; // Set the sys_id
gr.contact = ga.u_contact;
gr.u_authority_role = ga.u_responsibility;
gr.insert();
} else {
gs.info('Account not found: ' + sp[i]);
}
}
}
Note- you need to adjust the table you are suing for account name.
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2024 03:26 PM - edited 06-08-2024 03:27 PM
Hi @Community Alums ,
The issue might be in how you are setting the account value (sp[i]) in the company reference field. Reference fields expect a sys_id of the referenced record, not a display value or name.
Please find the updated code-
var sys_id = inputs.sysid;
var ga = new GlideRecord('sn_customerservice_bulkupdatecontactrelationship');
ga.addQuery('sys_id', sys_id);
ga.query();
if (ga.next()) {
var ac = ga.getValue('u_accounts');
var sp = ac.split(',');
for (var i = 0; i < sp.length; i++) {
// Query the sys_user table to get the sys_id of the account name
var userGR = new GlideRecord('sys_user'); // Use the appropriate table name
userGR.addQuery('name', sp[i].trim()); // Assuming 'name' holds the account names
userGR.query();
if (userGR.next()) {
var accountSysId = userGR.sys_id;
//create new record in sn_customerservice_contact_relationship
var gr = new GlideRecord('sn_customerservice_contact_relationship');
gr.initialize();
gr.company = accountSysId; // Set the sys_id
gr.contact = ga.u_contact;
gr.u_authority_role = ga.u_responsibility;
gr.insert();
} else {
gs.info('Account not found: ' + sp[i]);
}
}
}
Note- you need to adjust the table you are suing for account name.
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar