Workflow Action Script> Send Email with Customized PDF Title

  1. Use a Workflow with a Workflow Action Script to set a custom PDF title.Create a Custom Field to set the email subject, body and PDF title.
  2. Custom Email Subject
  • Label = Custom Email Subject (any)
  • ID = custbody_email_subject
  • Type = Free-Form Text
  1. Applies To > Sales Order
  2. Display > Subtab = Communication
  3. Custom Email Body
  • Label = Custom Email Subject (any)
  • ID = custbody_email_body
  • Type = Rich Text
  1. Applies To > Sales Order
  2. Display > Subtab = Communication
  3. Custom PDF Title
  • Label = Custom PDF Title (any)
  • ID = custbody_pdf_title
  • Type = Free-Form Text
  1. Applies To> Sales Order
  2. Display> Subtab = Communication
  3. Create a Workflow Action Script that will set the custom title and send an email.
  4. Create a JavaScript file with the following script. (File extension should be .js)
function setPDFName()
    {
     //Get the internal id of the transaction
     var id = nlapiGetRecordId();
 
     //Print the statement as a PDF file
     var file = nlapiPrintRecord('TRANSACTION', id, 'PDF');
 
     //Get the recipient email address
     var email = nlapiGetFieldValue('email'); 
     //Get the email subject from the custom field
     var body = nlapiGetFieldValue('custbody_email_subject'); 
     //Get the email body from the custom field
     var subject = nlapiGetFieldValue('custbody_email_body');
     //Get the custom PDF title from the custom field
     var pdftitle = nlapiGetFieldValue('custbody_pdf_title'); 
      var extension = ".pdf";
 
     //Concatenate the custom title and the PDF extension
     var filename = pdftitle.concat(extension);
     // Set the file name as the concatenated value
      file.setName(filename);
  
     //send the PDF as an attachment
     nlapiSendEmail('-5', email, subject, body, null, null, null, file); 
     //Change the internal id '-5' with any employee as a sender  
    }
  1. Go to Customization Scripting > Scripts > New
  2. Script File : Select the JavaScript file created in step 2.a
  3. Click Create Script Record
  4. Select Workflow Action
  5. Set fields as follows
  • Name = any (e.g. Send Email with Customized PDF Title)
  • Function = setPDFName
  1. Click Save and Deploy
  2. On the Script Deployment page set fields as follows.
  3. Applies To = Sales Order
  • Status = Released
  • Execute As Role = Administrator
  1. Check the checkbox Select All next to Roles under Audience tab.
  2. Create a Workflow that will trigger the Workflow Action Script.
  3. Go to CustomizationScripting Workflows New and set the following fields:
  • Name = Send Email with Customized PDF Title (any)
  • Record Type = Transaction
  • Sub type = Sales Order
  • Release Status = Testing (change this later to Released after testing the behavior)
  1. Select Event Based under Initiation tab
  2. Under Event Definition tab > select checkbox On Create and On View or Update
  3. Trigger Type = All
  4. Click Save
  5. On State1 select Add Button action from the New Action list with following settings:
  6. Trigger On = Before Record Load
  7. Parameter >Label = Send Email with Custom PDF Name (any)
  8. Condition> Custom Formula = {custbody_email_body} is not null and {custbody_email_subject} is not null and {custbody_pdf_title} is not null
  9. Check Condition Before Execution = Checked
  10. Click Save
  11. Create another state by clicking New State button and create a Transition from State 1 to State 2 as follows:
  12. Double Click on State 1 and under the Transitions tab click on New Transition
  • To = State 2
  • Execute on Button = Send Email with Custom PDF Name
  1. Click Save
  2. Click on State 2 select the custom action created in step 2.b (e.g. Send Email with Customized PDF Title) from the list of New Action and click Save
  3. Test the Workflow
  4. Go to any Sales Order
  5. Set a value for To Be E-mailed, Custom Email Subject, Custom Email Body and Custom PDF Title fields.
  6. Click Save
  7. Click on Send Email with Custom PDF Name

Leave a comment

Your email address will not be published. Required fields are marked *