GetAttachmentFromTemplate()
The GetAttachmentFromTemplate() function creates a file based on a given template and returns its content as a file object. This function does not attach the created file to the case. This created file object may be, for example, downloaded with DownloadFile() or sent with SendMessageEx() functions. CAUTION! If the template contains merge fields they will be filled with values from related fields on the case form.
Syntax
GetAttachmentFromTemplate(templateName,[fileName]);
Function arguments
- templateName – (String) a name of the template file;
- fileName – (String) [optional] a name of the resulting file. If ommited then the file name will be set to the template name with caseid before extension.
Return value
The GetAttachmentFromTemplate() function returns a file object.
Returns created file.
Examples
Example 1
This will create a document based on the „Contract.docx” template and assign it to a variable (a file object). Then the fileName property is set. At the end the file variable is passed to the DownloadFile() function.
file=GetAttachmentFromTemplate("Contract.docx"); file.fileName="Contract_"+[Number]+".docx"; DownloadFile(file);
Example 2
This will create a document based on the „Contract.docx” template with its name passed as a second parameter. Then the file variable is passed to the DownloadFile() function.
file=GetAttachmentFromTemplate("Contract.docx","Contract_"+[Number]+".docx"); DownloadFile(file);
Example 3
This will create a document based on the „Contract.docx” template with its name passed as a second parameter. Then it is added to an email object and sent as an attachment.
file=GetAttachmentFromTemplate("Contract.docx","Contract_"+[Number]+".docx"); mail.recipient=[User]; mail.subject=[Subject]; mail.message=[Message]; AddFileToList(mail.attachments,file); SendMessageEx(mail);