Anyway to update/change Emails (Message record) on...
# suitescript
a
Anyway to update/change Emails (Message record) on the fly before they go out? It looks like beforeSubmit events are not triggered in Message records...
s
guess is that message records are written AFTER the email is sent.
a
Not exactly, I can throw an error on beforeLoad and the email does not go out...but it is ugly...
s
nice! yea, that’s rough..
what are you trying to accomplish?
a
I need to stop some emails from being sent from a process that I can't script and does not trigger any UserEvent Script in the records being created but does trigger the Email Send for those records(Finance Charges)...
s
interesting.
c
There's gotta be a preference or field that controls it. They wouldn't send out emails randomly (most likely)
m
Can you change the recipient in beforeSubmit?
a
Message records do not trigger beforeSubmit UE.
Finance Charge creation do not trigger beforeSubmit UE on the record being created...
Only beforeLoad context.type = 'email' that is all I have access to...
I'm going another route to solve this, it was not possible to do what I needed to do with these limitations.
m
You absolutely can have beforeSubmit entry points on Message records. I gave this a quick try and recipient email is getting updated
Copy code
/**
 *@NApiVersion 2.1
 *@NScriptType UserEventScript
 */

define ([], () => ({
	beforeSubmit(context) {
		context.newRecord.setValue('recipientemail', 'blackhole@dev.null');
	}
}));
a
@michoel Not in messages generated automatically on record creates by NetSuite with the "To Be Emailed" flow...
From the Docs: • Only beforeLoad and afterSubmit user event entry point functions execute on the Message record type when a message is created by an inbound email case capture. Scripts set to execute on a beforeSubmit event do not execute. The same thing happens when Finance Charges are created and the Transaction is automatically emailed using the native "To Be Emailed" logic...
m
Oh never tried that