Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

My Custom Action Flow Designer is not working

Community Alums
Not applicable

 

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 

 

 

Ankur20_0-1717867736002.png

but Company field whose backend name is account is showing as Blank.

 

Ankur20_1-1717868039870.png

 

Kindly help in resolving the issue

1 ACCEPTED SOLUTION

Community Alums
Not applicable

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

View solution in original post

1 REPLY 1

Community Alums
Not applicable

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