Script to update field value from another field on a different table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2020 05:16 PM
I want to create a script, to add\change a specific value to a string field on my Account form from another string field on a different table.
On our Account form, we have a related list for Location (Account location). On the Account location form, we have a string field called 'country'. I want to take that value and add the 2-letter code for that country on another 'country' string field on our Account form. For example, if we have France as the country on our Account location on a specific Account, I'd like to add the 2-letter code for France (FR) to the country field on the Account record. I'd like to create the script so it looks specifically for France on the Account Location and add the 2-letter code (FR) to the other country field on the Account that country (France) is associated with.
Account table: customer_account
String field called 'country'
Account Location table: u_account_location
String field called 'country'

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2020 05:32 PM
Hi,
How these two tables are related? is this via reference field on the u_account_table? if yes, what is the reference field name?
Also, do you have Country code stored in any table? i.e. Location
Thanks & Regards,
Sharjeel
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2020 05:48 PM
Hi Sharjeel,
I'm not sure. I would assume they are related via the Account. Or Account name.
This is the information for the Account field on Account Location.
The country field type on both the Account and Account Location forms is a string value. Not a reference field to a specific table.
Not sure if this answers your questions.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2020 06:19 PM
Try this. I just prefixed static country code as FR. If this works fine then we will go for the next step of making this dynamic based on the country name.
Business Rule on Account Location
After Insert
var gr = new GlideRecord("customer_account");
gr.addQuery("sys_id", current.getValue('account'));
gr.setLimit(1);
gr.query();
gs.addInfoMessage("CUSTOMER ACCOUNT FOUND -- " + gr.getRowCount());
if(gr.next()) {
gs.addInfoMessage("CUSTOMER ACCOUNT -- " + gr.name);
gr.setValue('country', "FR -" + current.country);
gr.update();
}
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2020 03:16 PM
Hi Sharjeel,
Ended up doing something different. But thanks, this is helpful.