In my userevent script i have beforeLoad and after...
# suitescript
v
In my userevent script i have beforeLoad and aftersubmit function. my aftersubmit function is not called. what could be the reason? anyone please help?
k
Is the record submitted in the database or another before submitting is throwing?
v
i dont have beforesubmit. only beforeLoad and aftersubmit.
j
Share your code, if you can.
v
function aftersubmit(context){ log.debug('entering aftersubmit'); var newRecord = context.newRecord; var contextType = context.type; var isibfvpp = newRecord.getValue({fieldId : 'custrecord_12793_is_ibf_vpp'}); var senderId = runtime.getCurrentUser().id; var remindTreasuryRecipients = runtime.getCurrentScript().getParameter({ name: 'custscript_remind_treasury_recipients' }); log.debug('record id ',newRecord.id); if(contextType === 'edit'){ log.debug('aftersubmit : if edit'); if(isibfvpp){ log.debug('aftersubmit : if isibfvpp'); email.send({ author : senderId, recipients : remindTreasuryRecipients, body : 'The notice is sent to Treasury', subject : 'Notice sent to Treasury' }); } } newRecord.save(); return true; }
/**
* @NApiVersion 2.x * @NScriptType UserEventScript * @NModuleScope SameAccount */ //------------------------------------------------------------------ //Script Name: UE_Add_Button_Isabel_Status //Customer: CMB //Deployed on Record: Payment File Administration //Script Type: UserEvent (beforeLoad) //Description: Added three buttons on PFA and the functionality to those buttons is linked // via the client sctipt 'CMB_cs_pfa_functions.js' //Date: 05/10/2022 //Owner: Vennila Ramasamy //Last Modified Date: 17/10/2022 //Last Modified By: Vennila Ramasamy //Tags: //------------------------------------------------------------------ define([ 'N/ui/serverWidget', 'N/record', 'N/url', 'N/runtime', 'N/email' ], function(serverWidget,record,url,runtime,email){ function beforeLoad(context){ var newRecord = context.newRecord; var recordId = newRecord.id; var isabelStatus = newRecord.getValue({fieldId : 'custrecord_cmb_isabel_status'}); var remindTreasury = newRecord.getValue({fieldId : 'custrecord_cmb_notice_treasury'}); var isibfvpp = newRecord.getValue({fieldId : 'custrecord_12793_is_ibf_vpp'}); log.debug('isibfvpp',isibfvpp); var form = context.form; form.clientScriptModulePath = './CMB_cs_pfa_functions.js'; /*In the If condition, the field "Isabel status" is checked and the relevant button either "Sent to Isabel" or "Reset Isabel Status" is added via ClientScript CMB_cs_pfa_functions.js*/ if(!isabelStatus){ form.addButton({ id: 'custpage_senttoisabel', label: 'Sent to Isabel', functionName : 'checkIsabelStatus(' +recordId+ ')' }); }else{ form.addButton({ id : 'custpage_resetisabelstatus', label : 'Reset Isabel Status', functionName : 'uncheckIsabelStatus(' +recordId+ ')' }); } /*Obtaining the current user ID and an object that represents the current script to fetch the value of the script parameter*/ var senderId = runtime.getCurrentUser().id; var remindTreasuryRecipients = runtime.getCurrentScript().getParameter({ name: 'custscript_remind_treasury_recipients' }); log.debug('remindTreasuryRecipients',remindTreasuryRecipients); /*If the field "Treasury Reminded" is unchecked, the button "Remind Treasury" is added to send email notification to the employees(script parameters) and the field "Treasury Reminded" is checked via ClientScript CMB_cs_pfa_functions.js*/ if (!remindTreasury && isibfvpp){ log.debug('if, show the button'); form.addButton({ id : 'custpage_remindtreasury', label : 'Remind Treasury', functionName : 'remindTreasury(' +recordId+ ',' +senderId+ ',' +remindTreasuryRecipients+ ')' }); } return true; } function aftersubmit(context){ log.debug('entering aftersubmit'); var newRecord = context.newRecord; var contextType = context.type; var isibfvpp = newRecord.getValue({fieldId : 'custrecord_12793_is_ibf_vpp'}); var senderId = runtime.getCurrentUser().id; var remindTreasuryRecipients = runtime.getCurrentScript().getParameter({ name: 'custscript_remind_treasury_recipients' }); log.debug('record id ',newRecord.id); if(contextType === 'edit'){ log.debug('aftersubmit : if edit'); if(isibfvpp){ log.debug('aftersubmit : if isibfvpp'); email.send({ author : senderId, recipients : remindTreasuryRecipients, body : 'The notice is sent to Treasury', subject : 'Notice sent to Treasury' }); } } newRecord.save(); return true; } return{ beforeLoad : beforeLoad, aftersubmit : aftersubmit } } );
second one is the complete script
k
newRecord.save() is not needed. Could be that one
v
even without newRecord.save(), its not get fired.
the first log "entering aftersubmit" itself is not logged
j
In your return statement, you need to put: afterSubmit: aftersubmit NetSuite is looking for that capital S
v
oh ok.
@JessicaL thank you so much JEssica
j
You're welcome! I've made the same error and beat my head against my desk over it before. 😄
v
one more help. i want to send mail to two users thru script parameters. but i get SSS_INVALID_TO_EMAIL this error
what can i do?
ha ha
j
Is the parameter a text field with email addresses separated by commas? If so, you need to convert them into an array first.
"For multiple recipients, use an array of internal IDs or email addresses. You can use an array that contains a combination of internal IDs and email addresses. A maximum of 10 recipients (recipient + cc + bcc) is allowed."
v
the script parameter is a free-form text
I am entering the internal ids.
k
inactive employee?
j
As an array or just a list?
Even if you're entering it as an array, suitescript is probably grabbing the whole thing as a string. I'd use split() to convert it from string to array.
v
@Kyriakos Zisopoulos no its active employee
no, when i create the script parameters in the script deployment, i choose free-form text. i dont get your question "As an array or just a list?"
j
Are you entering in more than one email in the parameter?
On your deployment record.
b
the value you are entering in your free form text matters more than you expect
its being used to generate a string that is evaled, and the comma that you are probably using as a separator has meaning in function parameters
v
i am entering like this [2366,2387]. These are the ids of the employees. they will get the emails
j
Ok, great. When NetSuite grabs that from your parameters, it's probably turning it into this "[2366,2387]" which is a string that looks like an array and isn't actually an array. Instead, remove the brackets and keep the commas. Then in your script, use split to push each value based on comma into an actual array. That created array can then be used in your email.send function. let recipients = runtime.getCurrentScript().getParameter({ name: 'custscript_remind_treasury_recipients' }); let remindTreasuryRecipients = recipients.split(','); remindTreasuryRecipients = remindTreasuryRecipients.map(Number) [That last line may not be necessary. It converts each value in your array into a number. I cannot remember for the life of me if email.send accepts string versions of internalids.]
v
again a big Thank you @JessicaL. with out the brackets it works
✅ 1
j
😄 Great to hear! Happy I could help!
✅ 1
v
Sorry one more question. i send parameters from UE to CS. When logging, in UE there are two parameters. but in CS there is only one parameter (id) is received. how is it possible? and how to solve this?