//*****Function Definition -->String=formatDollarAmt(var1) // /************************************************************ Function: FormatDollarAmt Purpose: Format a dollar amount with dollar symbol, commas and decimal Half cents are rounded up on .005 and down on .004 ************************************************************/ function formatDollarAmt(s) { if (isNaN(parseFloat(s))) { return ""; } dblValue = parseFloat(s); blnSign = (dblValue == (dblValue = Math.abs(dblValue))); dblValue = Math.floor(dblValue*100+0.50000000001); intCents = dblValue%100; strCents = intCents.toString(); dblValue = Math.floor(dblValue/100).toString(); if(intCents<10) strCents = "0" + strCents; for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++) dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+ dblValue.substring(dblValue.length-(4*i+3)); RetVal = (((blnSign)?'':'-') + '$' + dblValue + '.' + strCents); return RetVal; }
This allows you to dynamically change the email that you are going to send. For example. You could have multiple emailBuilders. Call them something different though. Leave emailBuilder in the email nodes. Then, right before you get to the email node, you can decide what email you want to send and assign it to emailBuilder. So if I have an XML email structure for situation A and one for B, I just say emailBuilder = emailBuilderForA right before the email node. Then all of that data is what will be used in the email node. Your flows can look far more elegant with this and you can do much more powerful things and not risk emailing a real person during testing. You don't need to restructure your code when you deploy. Just switch the testing flag to false and it goes into production mode.
Never re-write HTML emails over and over again. Write it one time and assign it to a function. Then have the sendEmailContent function build it into your styled and beautiful email template for you...
//I have a bool flag called isTesting. I set to true when I'm testing it and don't want to send real emails. emailBuilder = ( //XML TYPE -- insert elements into the to, cc, bcc fields xx~! Please do not reply to this email. This is an automatic notification generated by ProcessFlow ); //all of these sendEmail... functions take the emailBuilder as the input sendEmailTo = ( //I have the same for CC and BCC - XML TYPES function(input) { var output = ""; var tmp; if(isTesting){ tmp = input.test.to.children(); } else { tmp = input.prod.to.children(); } for (var i in tmp) { output += tmp + ", " } return output; } ); sendEmailSubject = ( function(input) { var output = ""; if(isTesting){ output += input.test.subjectPrefix; } output += input.subject; return output; } ); sendEmailContent = ( function(input) { var output = ""; var tmp = input.body.children(); for (var i in tmp) { switch (tmp.name().toString()) { case "paragraph": output += Paragraph(tmp); break; case "button": output += Button(tmp.text, tmp.url); break; default: break; } } return output; } ); Paragraph = ( //XML TYPE - Function to format the HTML for a paragraph function (input) { var text = input; var output = ""; output += " " button="(" label="inLabel;" url="inURL;" xmlns:w="\'urn:schemas-microsoft-com:office:word\'';" arcsize="\'5%\'" strokecolor="\'#EB7035\'" fillcolor="\'#EB7035\'">"; output += ""; output += " "; output += inLabel; output += ""; output += ""; output += "<\![endif]-->"; output += "<\!--[if !mso]>" +=""; output += inLabel; output += ""; output+=""; output += "<\![endif]-->"; return output; } ); // DEMO TO USE THIS // - First add the addresses emailBuilder.prod.to.appendChild( {approverList.primary.person.(id.ein ==approverList.current.ein).contact.email.toString()} ); emailBuilder.test.to.appendChild( {variableWithMyEmail} ); // - next add the subject and body emailBuilder.subject = tmpCurrent.name.first + " Position Approval Action Needed"; emailBuilder.body.prependChild( Dear {tmpCurrent.name.first.text()}, please check your LTM inbasket for action. ); emailBuilder.body.appendChild( Some more body text. ); emailBuilder.body.appendChild( Click Mewww.google.com ); //Then in the email node Set the following: //TO: <!--sendEmailTo(emailBuilder)--> //CC: <!--sendEmailCC(emailBuilder)--> //BCC: <!--sendEmailBCC(emailBuilder)--> //FROM: <!--fromEmailVariable--> //SUBJECT: <!--sendEmailSubject(emailBuilder)--> //BODY: This is my default template. If you look closely, you'll see sendEmailContent(emailBuilder) in there. //There is another function in there I use for highlighted alerts at the bottom, if you want that, let me know. MailStyler - New xxx Department of xxx xxx xxx Information Systems () Dear , <!--sendEmailContent(emailBuilder)--> <!--sendEmailAlerts(emailBuilder)--> The following is for xxxx use only: Workunit: <!--oWorkUnit--> ProductLine: <!--appProdline--> Host: <!--host-->
" button="(" label="inLabel;" url="inURL;" xmlns:w="\'urn:schemas-microsoft-com:office:word\'';" arcsize="\'5%\'" strokecolor="\'#EB7035\'" fillcolor="\'#EB7035\'">"; output += ""; output += "
xxx Department of xxx
xxx xxx Information Systems ()
Dear ,
The following is for xxxx use only:
Here is an image of what you will see. Sorry I scribbled up the picture. Non of that info was probably super sensitive but I really just feel like being overly cautious and not giving out too much info. The yellow part at the bottom of the email is the missing piece I didn't include. I could, though if anyone wants. I think I made the font look nicer too since I last used this.
I forgot to mention that the test flag also makes it so that the subject line has the option of adding a prefix to it. I add a prefix like "xx~!". That way I can setup and outlook filter to put my test emails in it's own box. Testing can clutter your inbox fast. You can also prepend it with a timestamp or whatever you want...
So making email nodes for me is super fast, easy and reliable. Now, instead of formatting a custom email each time, I just think I want a paragraph of text, followed by another paragraph, flowed by a button and then a paragraph. And boom, my code beautifully creates it all for me.
As you can see, all of my email nodes will look IDENTICAL to this. All of the content is determined and setup in my code. It is stored in XML in the start node. So it will persist if the process is suspended, like from a userAction node.
I'd rather do this with objects and methods (I had it like that originally). But those don't persist through things like userActions. So I rebuilt using XML. I did it quickly. I'd rather have it be instantiable and with methods. I'll be researching if there is a good way to do that with XML...
Thank you Geoff - I need something just like this, but haven't started looking for it yet. I'll need to decipher (review) it later, to make sure I understand the code. If I have questions, may I email you?
Thanks -Joan