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.

How to populate realated Location field as per the selected account on case form?

aakankshapl
Tera Guru

Hello,
On the csm case form there are 2 fields named as account (customer_account) and location (cmn_location) both fields are reference fields. So basically want to populate the location which is related to that account. Please help me into that..

aakankshapl_0-1710497723572.png

aakankshapl_1-1710497768327.png

 

 

9 REPLIES 9

Amit Pandey
Kilo Sage

Hi @aakankshapl 

 

I think you will have to make a reference on cmn_location with customer_account table. So as soon as you will fill the account value on case form, location will be populated automatically. 

 

Please try once.

 

Regards,

Amit

Hi @Amit Pandey
 
Thank you for you suggestion.

aakankshapl
Tera Guru

Hello Everyone,
I got the solution to problem.

So on my case form 2 fields Account and Location and both field are reference to customer_account and cmn_location. basically I wanted to populate the location when I select any account in account field, that location should be related to them. So I locate the common relationship between these 2  tables that was Company ID. 
For that I created a script include and call that script include in location field reference qualifier. Below is the code of scipt include:

 

 

var LocationFilter = Class.create();
LocationFilter.prototype = {
    initialize: function() {
    },

	refqualassignedto: function(account) {
    //var accountName = 'Puma'; //this.getParameter('account'); // your assignment group variable name
    var location = [];
    if (account != '') {
        var grAcc = new GlideRecord('customer_account');
        grAcc.addQuery('sys_id', account);
        grAcc.query();
        if (grAcc.next()) {
            var grLoc = new GlideRecord('cmn_location');
            grLoc.addQuery('company.u_company_id', grAcc.u_company_id);
            grLoc.query();
			gs.info('test1'+ grLoc.getRowCount());
            while (grLoc.next()) {
                location.push(grLoc.getUniqueValue());
            }
        }

        return 'sys_idIN' + location;
    } 

},

    type: 'LocationFilter',
};

 

 

And call the below script include in location fields reference qualifier:
javascript:new global.LocationFilter().refqualassignedto(current.account);

 

Amit Pandey
Kilo Sage

@Bingo @aakankshapl 😇

 

You found a solution to your own problem and shared it here to help others who might face the same issue in the future. Nice gesture! Keep it up.

 

Regards,

Amit

 

 

Thank You @Amit Pandey 😊