My company is using the Dunning Letters SuiteApp a...
# suitescript
m
My company is using the Dunning Letters SuiteApp and I'm trying to automatically add specific dunning recipients (a small handful of specific contact records representing internal employees/inboxes, not dynamic based on customer info) to customer records upon creation. I found one SuiteAnswers article that suggests a SS 1.0 snippet in a
beforeLoad
UE script:
Copy code
if (type == 'create'){‌
    nlapiSetLineItemValue('recmachcustrecord_3805_dunning_recipient_cust', 'custrecord_3805_dunning_recipient_cont','1','29');
}
I translated that into SS 2.1 w/
setSublistValue
in place of
nlapiSetLineItemValue
and it works fine when creating a customer in the UI, but I get an
UNEXPECTED_ERROR
pointing to that method when creating a customer via CSV import. I also get the same error when using it in
beforeSubmit
. (In
afterSubmit
, I don't get an error, but it also requires me to load/save it explicitly, which obviously isn't available in `beforeLoad`/`beforeSubmit` when creating) Is there some reason I'm unaware of (and can't seem to find) that explains why I can't use
setSublistValue
in `beforeLoad`/`beforeSubmit` when creating customers via CSV? And are other execution contexts (e.g. SOAP/REST Web Services) going to have similar problems?
From a DM that someone sent me (keeping their anonymity, since they didn't directly reply):
The
setSublistValue
function modifies a sublist line item in a record, and it's not allowed in
beforeLoad
because the record isn't fully initialized at that point in the script execution context.
As for why you're encountering an error while importing a CSV, it might be because the
beforeSubmit
context also doesn't work with CSV imports as the whole file is processed as a batch operation. Hence, the record object is not fully available and is not modifiable in the same way as it is when you are creating a record in the UI.
I think you can use solution for your problem a Scheduled Script or Map/Reduce script to process new customers and add the necessary Dunning Letter recipients. This would involve periodically scanning for newly created customer records and adding the required recipients.
I kinda understand why NS might disallow
setSublistValue
in
beforeLoad
when not in a UI context. But it still feels weird that I can't do it in
beforeSubmit
, especially since I'm not relying on any data from that record or any other record (it's for all customers being created). If some new requirement rules out my use of the
afterSubmit
function, then I might go with a SS or MR.
e
CSV imports are inline edits (
XEDIT
events), and sublists are not available during inline edits. Your script could detect the CSV execution context and load the record before you modified the sublists, and you would most likely want to do that during
afterSubmit
.
m
@erictgrubaugh Thanks for the insight. When you say "CSV imports are inline edits (
XEDIT
events)", do you mean that literally? Or are you saying that it behaves the same way? I only ask because I am logging the UE type in my script during testing and the CSV imports come in as
CREATE
or
EDIT
instead of
XEDIT
. Either way, this is at least a good mental model for me to keep handy. I really appreciate your help (both here and in the NS community in general).
e
Hm I actually would have expected it to be literally, but appears not.