This topic contains 3 replies, has 0 voices, and was last updated by wsangster 6 years, 8 months ago.
-
AuthorPosts
-
March 19, 2018 at 8:49 am #17996
jsheplerI’m trying to implement code to delete a customer address. I’ve been able to remove the address from the customer, but the (now orphaned) address record is left behind.
I tried doing record.removeSublistSubrecord but that didn’t work. No error, but didn’t remove the address subrecord.
I thought maybe I have to save the customer record afterward. That didn’t work either. Again, no errors, but address was not removed.
I then added a call to remove that sublist line. That removed the sublist line – the address no longer shows under that customer. But the address record itself is still there – record.load retrieves it.
Doing a record.delete returns an error about invalid record type, even though it works fine for record.load.
I do understand there are different ids for the address. The sublist actually has 3 id fields with identical values: id, internalid, addressid. The sublist field “addressbookaddress_key” has the id of the address record. Doing a record.load of type address and that id gets the address. I pass the correct id to the below function, used to find the correct sublist line. I use the other id when loading the record.
Here’s a snippet of code that shows what I’m doing:
Code:
function DeleteCustomerAddress(customerId, addressId)
{
var customerRec = record.load({ type: record.Type.CUSTOMER, id: customerId });
var line = customerRec.findSublistLineWithValue({ sublistId: “addressbook”, fieldId: “addressid”, value: addressId. });log.debug(“delete address”, { customerId: customerId, addressId: addressId, line: line });
if (line == -1)
throw “address id ” + addressId + ” not found under customer id ” + customerId;customerRec.removeSublistSubrecord({ sublistId: “addressbook”, fieldId: “addressbookaddress”, line: line });
customerRec.removeLine({ sublistId: “addressbook”, line: line });
customerRec.save();log.debug(“deleted”, “”);
}
This code works as far as removing the line, but the actual address record remains behind.I can’t imagine that it’s ok to leave these orphaned addresses behind. Am I missing something?
This is a cached copy. Click here to see the original post. -
March 19, 2018 at 11:22 am #17997
wsangsterI used CSV imports to remove and add multiple addresses. After you pick your file and you are on the “Import Options” screen. Click the Advanced Options and you’ll see a box for Overwrite Sublists.
I’ve never tried it with any code yet. Still learning that.
-
March 19, 2018 at 12:06 pm #17998
jsheplerSorry, this will be an automated thing via a restlet so a manual import isn’t a practical solution for me.
But I’m curious, overwriting the sublist – if you’re overwriting the sublist, that sounds like it’s just overwriting the mappings. Wouldn’t it still leave the address records themselves behind? How do we clean those out?
-
March 19, 2018 at 12:18 pm #17999
wsangsterHere is a SuiteAnswer I found that told me what to do
https://netsuite.custhelp.com/app/an…omer%20records
I have also used Overwrite Missing Fields for some of my imports to delete things.
OVERWRITE MISSING FIELDS
For updates, enable this option to clear NetSuite fields mapped to CSV file fields that do not contain data.
-
AuthorPosts
You must be logged in to reply to this topic.