RE: Removing Subsidiaries in Customer-Subsidiary Relationship

Recently, I was tasked with removing X subsidiary from all of our existing customers, and I was unable to find anyway to do this efficiently. I tried using CSV import and using the “overwrite sublists” feature, however I don’t think it works, because in the customer-subsidiary sublist it cannot remove all the subsidiaries, therefore it cannot replace the sublist with one I put into the CSV.

 

I was wondering if there was anyway to automate or possibly do this without having to manually go through all of our existing customers and removing the subsidiary from their customer-subsidiary relationship. Any help would be greatly appreciated!

Jackie Rookie Asked on December 5, 2023 in How To's.
Add Comment
2 Answers

Just adding onto this, I have tried to come up with a solution using SuiteScript to enter in and automatically remove the subsidiaries that I designate after I hit “edit” on a customers file, however I cannot seem to get it to work, this is the script so far.

/**

* @NApiVersion 2.x

* @NScriptType UserEventScript

*/

define(['N/log', 'N/record'],

function (log, record) {

function beforeSubmit(context) {

try {

if (context.type === context.UserEventType.EDIT) {

// Get the customer record

var customerRecord = context.newRecord;
// Specify the subsidiary internal ID you want to remove

var subsidiaryToRemove = '3'; // Replace with the actual subsidiary internal ID
// Get the number of subsidiaries on the Subsidiaries sublist

var subsidiariesCount = customerRecord.getLineCount({

sublistId: 'subsidiaries'

});
// Loop through each subsidiary on the Subsidiaries sublist

for (var line = subsidiariesCount - 1; line >= 0; line--) {

// Get the subsidiary internal ID from the sublist

var subsidiaryId = customerRecord.getSublistValue({

sublistId: 'subsidiaries',

fieldId: 'subsidiary',

line: line

});
// If the current subsidiary matches the one to be removed, remove the line

if (subsidiaryId === subsidiaryToRemove && subsidiariesCount > 1) {

customerRecord.removeLine({

sublistId: 'subsidiaries',

line: line

});
log.debug({

title: 'Subsidiary Removed',

details: 'Subsidiary ' + subsidiaryToRemove + ' removed from customer record.'

});

}

}

}

} catch (e) {

log.error({

title: 'Error',

details: e.toString()

});

}

}
return {

beforeSubmit: beforeSubmit

};

}

);

 

I would appreciate any help/insight, thanks again

Rookie Answered on December 5, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.