Deleting records and recording the reason/memo (SS1.0 & SS2.0)
This isn’t a question, but I wanted to share this information so that others can find it if they are stuck on the same thing I was.
I was looking for a way to delete records in SuiteScript (2.0 preferably) and record the reason for the deletion, as you would when deleting through the UI.
I was directed by NS Support to SuiteAnswers article 10470 which suggested that at least with SS1.0 it was possible to pass the delete reason (id) and memo (string) to nlapiDeleteRecord using the initializationValues object. Upon testing this solution, I found that this does not work and the delete reason is left as the default.
Further searching led me to page 86 of the 2015.2 release notes. Here I discovered that it is possible to set the two values (reason id and memo) by loading the record and saving it prior to calling nlapiDeleteRecord. This solution works to save the delete reason.
I tried the same thing with SuiteScript 2.0 and it also works, though this doesn’t appear to be documented anywhere.
For reference, here are my tests:
/* SuiteScript 1.0 */ // Doesn't work :( nlapiDeleteRecord('invoice', invoice_id, {deletionreason: 1, deletionreasonmemo: 'SS1.0 Delete reason saved using Initialization Values'}); // Works! var inv = nlapiLoadRecord('invoice', invoice_id); inv.setFieldValue('deletionreason', 1); // This is REQUIRED or the memo isn't set... inv.setFieldValue('deletionreasonmemo', 'SS1.0 Delete reason saved using Load/Save'); nlapiSubmitRecord(inv); nlapiDeleteRecord('invoice', invoice_id); /* SuiteScript 2.0 */ // Doesn't work :( record.delete({ type: record.Type.INVOICE, id: invoice_id, defaultValues: { deletionreason: 1, deletionreasonmemo: 'SS2.0 Delete reason saved using Default Values' } }); // Works! var inv = record.load({ type: record.Type.INVOICE, id: invoice_id }); inv.setValue({fieldId: 'deletionreason', value: 1}); inv.setValue({fieldId: 'deletionreasonmemo', value: 'SS2.0 Delete reason saved using Load/Save'}); inv.save(); record.delete({ type: record.Type.INVOICE, id: invoice_id });
Working Solutions
/* SuiteScript 1.0 */ var inv = nlapiLoadRecord('invoice', invoice_id); inv.setFieldValue('deletionreason', 1); // This is REQUIRED or the memo isn't set... inv.setFieldValue('deletionreasonmemo', 'SS1.0 Delete reason saved using Load/Save'); nlapiSubmitRecord(inv); nlapiDeleteRecord('invoice', invoice_id); /* SuiteScript 2.0 */ var inv = record.load({ type: record.Type.INVOICE, id: invoice_id }); inv.setValue({fieldId: 'deletionreason', value: 1}); inv.setValue({fieldId: 'deletionreasonmemo', value: 'SS2.0 Delete reason saved using Load/Save'}); inv.save(); record.delete({ type: record.Type.INVOICE, id: invoice_id });
This is great to know. Thanks for sharing!
KevinJ Of Kansas
This very useful, thanks Jen!
jen
Thanks. I wasn’t sure how to mark it as best but I see you’ve done that (thank you). Still getting used to this forum. Trying to get code to format properly is ….challenging?