Dependent field

tanaya
Tera Contributor

Hi All,

 

On the incident form, there is a Location and an Account field. I want to display the Locations based on the Account selected, i.e. only the locations which are for the selected account will show. I have tried adding 'company' as the dependent field:

tanaya_0-1719568777088.png

 

However, that works only for some accounts. For others, it shows either some or no locations at all.

 

I also tried creating a Dictionary Override for the Incident table (removing the default dependent) which looks like this: 

tanaya_1-1719568868612.png

But this is not working as well. Can anyone please let me know if I am doing anything wrong, or any alternative solution?

 

Thanks.

1 REPLY 1

Dnyaneshwaree
Mega Sage

hello @tanaya ,

Try the OnChange (and , or onload)Client script by refering and updating below script:

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
  return;
}
var accountFor = new GlideRecord('account');
accountFor.addQuery('sys_id',newValue);
accountFor.query();
while(accountFor.next()) {
g_form.setValue('location',accountFor.location);
}
}

 


Also refer the below article for similar requirement:
https://www.servicenow.com/community/developer-forum/autofill-location-based-on-user/m-p/2142708
https://www.servicenow.com/community/developer-forum/need-to-populate-location-field-based-on-the-co...
https://www.servicenow.com/community/itsm-forum/auto-populate-location-location-based-on-the-users-s...


If my solution helps you any way then mark it as accepted and helpful.

Thank You!!