Script to update field value from another field on a different table

MStritt
Tera Guru

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'

find_real_file.png

find_real_file.png

Account Location table: u_account_location
String field called 'country'

find_real_file.png

find_real_file.png

 

 

5 REPLIES 5

MrMuhammad
Giga Sage

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

Regards,
Muhammad

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. 

find_real_file.png

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.

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();
}
Regards,
Muhammad

Hi Sharjeel,

Ended up doing something different. But thanks, this is helpful.