I am creating my first SuiteScript and I want to create a function that checks two different records (one in a customer record and one in a contact record) on submit and verifies that a specific checkbox field in each of those have been checked.
It will also need to validate if two triggered emails have been sent by looking for those custom field check boxes in the customer record.
If both check boxes and both triggered emails have been sent, then the script allows the user to submit their data for that customer without any action.
If both check boxes are filled but neither email has been sent, then on submit, the script sends out the first email to the contact that was assigned the appropriate custom role.
If the customer record check box is selected, but the client check box is not selected, the script triggers an alert that stops the form from being submitted and alerts the user that they need to fill out that field in the client record and then re-submit their forms.
If the customer record check box is not selected, then the script does nothing and the user can submit the form without interference.
I have found some triggered email script samples, but I am not sure I am going in the correct direction. Below is the code I have so far.
function beforeProSupport (type) { var proSupportMail = custscript_val_proSupport; var proSupport_set = nlapiGetFieldValue('custmomer.custentitysc_type'); var proSupport_confirm = nlapiGetFieldValue('contact.custentity30'); //boolean value to check if Welcome Message was sent before var bolTermSent = (nlapiGetFieldValue('proServices_terms_email') && nlapiGetFieldValue('proServices_terms_email')=='T')?true:false; var bolWelSent = (nlapiGetFieldValue('proServices_welcome_email') && nlapiGetFieldValue('proServices_welcome_email')=='T')?true:false; //internal ID of email template to merge with. var mailTemplateID = '3'; //uses bolTermSent and bolWelSent functions and checks the status of the two if ((!bolTermSent || !bolWelSent) && (proSupport_set.contains(status) && proSupport_confirm.contains(status)) { { // Get customer Point Of Contact email and send first email to them. //conduct mail merge with this customer record by calling //nlapiMergeRecord() method. //nlapiGetNewRecord().getId() returns internal ID of this record. var mail = nlapiMergeRecord(mailTemplateID,'customer', nlapiGetNewRecord().getId()); //return value of Subject from Email Template var sbj = mail.getName(); //return value of Message body from Email Template var msg = mail.getValue(); //set sendto as Internal ID of this customer. // - Using this method allows customers' response (When Reply is used) is automatically logged // - This method also automatically attaches this message to THIS customer var sendto = nlapiGetNewRecord().getId(); //Send out the email using nlapiSendEmail nlapiSendEmail('-5',sendto,sbj,msg,null,null,null,null); //update Welcome Message Sent flag. nlapiSubmitField('customer',nlapiGetNewRecord().getId(),'custentity_welcome_email','T'); } } I know that this is probably a much larger question than normal, so any links to resources that would help would be great, as well as any corrections to the code above. All this code does is, in theory, validate if any of the previous emails have been sent and then validate if the fields have been filled and then send the first email. Unfortunately it is not working and I am at a bit of a loss. So any help would be much appreciated. Thanks again!