- 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.
- Custom Email Subject
- Label = Custom Email Subject (any)
- ID = custbody_email_subject
- Type = Free-Form Text
- Applies To > Sales Order
- Display > Subtab = Communication
- Custom Email Body
- Label = Custom Email Subject (any)
- ID = custbody_email_body
- Type = Rich Text
- Applies To > Sales Order
- Display > Subtab = Communication
- Custom PDF Title
- Label = Custom PDF Title (any)
- ID = custbody_pdf_title
- Type = Free-Form Text
- Applies To> Sales Order
- Display> Subtab = Communication
- Create a Workflow Action Script that will set the custom title and send an email.
- 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
}
- Go to Customization > Scripting > Scripts > New
- Script File : Select the JavaScript file created in step 2.a
- Click Create Script Record
- Select Workflow Action
- Set fields as follows
- Name = any (e.g. Send Email with Customized PDF Title)
- Function = setPDFName
- Click Save and Deploy
- On the Script Deployment page set fields as follows.
- Applies To = Sales Order
- Status = Released
- Execute As Role = Administrator
- Check the checkbox Select All next to Roles under Audience tab.
- Create a Workflow that will trigger the Workflow Action Script.
- Go to Customization> Scripting > 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)
- Select Event Based under Initiation tab
- Under Event Definition tab > select checkbox On Create and On View or Update
- Trigger Type = All
- Click Save
- On State1 select Add Button action from the New Action list with following settings:
- Trigger On = Before Record Load
- Parameter >Label = Send Email with Custom PDF Name (any)
- Condition> Custom Formula = {custbody_email_body} is not null and {custbody_email_subject} is not null and {custbody_pdf_title} is not null
- Check Condition Before Execution = Checked
- Click Save
- Create another state by clicking New State button and create a Transition from State 1 to State 2 as follows:
- 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
- Click Save
- 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
- Test the Workflow
- Go to any Sales Order
- Set a value for To Be E-mailed, Custom Email Subject, Custom Email Body and Custom PDF Title fields.
- Click Save
- Click on Send Email with Custom PDF Name