Fix script

Kanika4
Tera Contributor

HI

 

I need to write a fix script to fix the backdated data for 18 months.

 

So the managers on the form are not in sync with the team members related list.

They dont match.

So I need to update the managers on the team members related list with the managers on the account table.

 

Can you please help me with the script ?

4 REPLIES 4

Mark Manders
Mega Patron

Can you share how your data is in the system? OOB there is no 'manager' on account level. And the 'team members' related list only allows for adding a user and the responsibility (OOB). It would help in knowing exactly what you are trying to do.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

It is OOB customer_account table. The account managers on the table should match the user and responsibility on the team members related lists.

 

at the moment, they are not in synch. I need a script to fix that.

Sid_Takali
Kilo Patron
Kilo Patron

Hi @Kanika4 You mean you want to sync Team Members Related List with Vendor Manager on a Account "customer_account" Table?

Sid_Takali_0-1725187351105.png

 

abirakundu23
Mega Sage

Please try below code as per your requirement
var MonthsAgo = new GlideDateTime();
MonthsAgo.addMonths(-18);

// Create a GlideRecord object for the required table
var MemberGR = new GlideRecord('team_member'); // Replace table name
MemberGR.addQuery('sys_created_on', '>=', eighteenMonthsAgo); // filter by creation date
MemberGR.query();

while (MemberGR.next()) {
// Create a GlideRecord object for the account table
var accountGR = new GlideRecord('account'); // your table name
if (accountGR.get(MemberGR.account)) {
// Check if the manager needs to be updated
if (MemberGR.manager != accountGR.manager) {
gs.info('Updating team member ' + MemberGR.sys_id + ' manager from ' + MemberGR.manager + ' to ' + accountGR.manager);
MemberGR.manager = accountGR.manager;
MemberGR.update(); // Update the record
}
}
}

Please mark helpful & correct answer its worthy for you.