Update new field on all Accounts with the Account Name

MStritt
Tera Guru

I've created a new text field on my Account table called 'Account Friendly Name'. The default for this new field on all new Accounts created moving forward will be the actual value of the 'Account Name'. For all current Accounts, I need to update the Account Friendly Name with the current Account name. I'm assuming I would need to run a script of some sort, but don't have the ability to do that. Anyone provide sample code to use to update all current Accounts?

 

Account Friendly Name = u_account_friendly_name

Table / Account [customer_account]

Account Name = name 

Table / Company [core_company]

1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

You need to run a fix script or background script to update the existing accounts.

var ca = new GlideRecord('customer_account');
ca.setLimit(2);
ca.query();

while (ca.next())
{
ca.u_account_friendly_name = ca.<account name field>;
ca.update();
}

 Above is an example script. I have limit it to two, so that you test if works 


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

8 REPLIES 8

SanjivMeher
Kilo Patron
Kilo Patron

You need to run a fix script or background script to update the existing accounts.

var ca = new GlideRecord('customer_account');
ca.setLimit(2);
ca.query();

while (ca.next())
{
ca.u_account_friendly_name = ca.<account name field>;
ca.update();
}

 Above is an example script. I have limit it to two, so that you test if works 


Please mark this response as correct or helpful if it assisted you with your question.

I'm getting the following:

MStritt_0-1701826948377.png

 

OK. I got it to work. I changed line 7 to show:

ca.u_account_friendly_name = ca.name;

 

So, I would just remove line 2 from the code, and just run that to update all Accounts I would assume?

 

Right. Try it on a Dev Instance just to make sure it is working as expected.


Please mark this response as correct or helpful if it assisted you with your question.