Page 1 of 1
Conditioning email attachments
Posted: Fri Sep 30, 2011 3:16 pm
by Submariner
Hi
How does one condition whether an attachment will be attached to an email or not.
I have a project whereby an SQL is run followed by a Write Excel task to convert the data to EXCEL - and then to finally send this via email as an attachment.
I would like to conditionally attach it to the email only if there is data - otherwise not.
Currently, when I run my project, the sql convert to an EXCEL produces this error if there is no data:
[8099 - Convert Ctl Grp Negative] An unexpected error occurred. Your InputStream was neither an OLE2 stream, nor an OOXML stream I can set on a variable if this error occurs and continue the next process.
Depending on the variable value, I would like to attach an attachment to the email.
Currently, the attributes for an attachment do not have the ability to condition it.
Thanks in advance
Re: Conditioning email attachments
Posted: Mon Oct 03, 2011 3:26 pm
by RElliott63
I usually perform my Emails with the attached Job Call:
Code: Select all<project name="Send Email" mainModule="Main" version="1.0">
<variable name="emlHeader" value=" " description="Project header info" />
<variable name="emlSubject" value=" " description="Project Subject" />
<variable name="emlMessage" value=" " description="Project Message" />
<variable name="emlToList" value=" " description="Project Email to List" />
<variable name="emlAttach" value=" " description="Project Attachment" />
<module name="Main">
<sendEmail label="Send Notification" resourceId="${emlResource}" toList="${emlToList}" version="2.0" executeOnlyIf="'${emlAttach}' eq ' '" >
<from address="${emlFromAddress}" />
<subject>
<![CDATA[${emlHeader} - ${emlSubject} ]]>
</subject>
<message>
<![CDATA[
${emlMessage}
]]>
</message>
</sendEmail>
<sendEmail label="Send Notification" resourceId="${emlResource}" toList="${emlToList}" version="2.0" executeOnlyIf="'${emlAttach}' ne ' '" >
<from address="${emlFromAddress" />
<subject>
<![CDATA[${emlHeader} - ${emlSubject} ]]>
</subject>
<message>
<![CDATA[
${emlMessage}
]]>
</message>
<attachment file="${emlAttach}" />
</sendEmail>
</module>
<description>Send an Email</description>
</project>
That way I can condition based on Successful ...
Code: Select all <callProject label="Notify Success" version="1.0" project="/Utilities/Send Email" runInSameJob="true" inheritUserVariables="true" returnUserVariables="true" onError="setVariable:Error=1" executeOnlyIf="( ${Error} eq 0 ) and ( '${Notify_Success}' ne '' )">
<variable name="emlHeader" value="${JobName} : ${JobType}" />
<variable name="emlSubject" value="File Ready for Pickup" />
<variable name="emlMessage" value="
File Type: ${FileType} ${system.carriageReturn}
File Name: ${ThisFile:name} ${system.carriageReturn}
${system.carriageReturn}
This file is ready for transfer!" />
<variable name="emlToList" value="${Notify_Success}" />
</callProject>
or Unsuccessful:
Code: Select all <callProject label="Notify Fail" version="1.0" project="/Utilities/Send Email" runInSameJob="true" inheritUserVariables="true" returnUserVariables="true" onError="setVariable:Error=1" executeOnlyIf="( ${Error} gt 0 ) and ( '${Notify_Fail}' ne '' )">
<variable name="emlHeader" value="${JobName} : ${JobType}" />
<variable name="emlSubject" value="File Transfer Failure" />
<variable name="emlMessage" value="
File Type: ${FileType} ${system.carriageReturn}
File Name: ${ThisFile:name} ${system.carriageReturn}
${system.carriageReturn}
This file is NOT ready for transfer! Please see previous messages for root cause." />
<variable name="emlToList" value="${Notify_Fail}" />
<variable name="emlAttach" value="${system.job.log}" />
</callProject>
Hope this helps!
-Rick
Re: Conditioning email attachments
Posted: Tue Oct 04, 2011 8:10 am
by Submariner
Interesting concepts! Thanks. This is helpful.
Still, it would be nice in a future release to include the ability to conditionally attach the attachment based on a variable.
But I will employ this fix of yours for now.
Thx