PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 08/16/2016 8:04 AM by  Joan Herzfeldt
javascript functions in processflow
 9 Replies
Sort:
You are not authorized to post a reply.
Author Messages
Maynard F.
Technical Consultant
Friendly IT Consulting
Basic Member
(22 points)
Basic Member
Posts:10


Send Message:

--
10/18/2013 8:41 AM
    Hello.  I would like to see some of the custom functions that PFI users have developed.  Specifially, I am wanting a function that will format a numeric field into an alpha numeric field complete with currency sign, commas and a decimal point.  Any other functions will be appreciated.  Please reply or post the code and tell me where to find it.  Thank you.
    Tags: javascript function number format
    Kyle Jorgensen
    Programmer/Analyst
    WoodmenLife
    Veteran Member
    (308 points)
    Veteran Member
    Posts:114


    Send Message:

    --
    10/18/2013 9:26 AM
    //*****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))+&#39;,&#39;+
                dblValue.substring(dblValue.length-(4*i+3));
        RetVal = (((blnSign)?&#39;&#39;:&#39;-&#39;) + &#39;$&#39; + dblValue + &#39;.&#39; + strCents);
        return RetVal;
        
    } 
    
    Kyle Jorgensen
    Programmer/Analyst
    WoodmenLife
    Veteran Member
    (308 points)
    Veteran Member
    Posts:114


    Send Message:

    --
    10/18/2013 9:30 AM
    Heh, even though I used the 'code' tags it didn't like the single quote marks in the "RetVal" assignment line. Just replace each "'" with single quotes.
    Kyle Jorgensen
    Programmer/Analyst
    WoodmenLife
    Veteran Member
    (308 points)
    Veteran Member
    Posts:114


    Send Message:

    --
    10/18/2013 9:33 AM
    Dang...it didn't like that either. Replace each "ampersand-pound-thirtynine-semicolon" with single quotes.
    Maynard F.
    Technical Consultant
    Friendly IT Consulting
    Basic Member
    (22 points)
    Basic Member
    Posts:10


    Send Message:

    --
    10/18/2013 9:45 AM
    Thanks Kyle.  Is this function one that you have used before, or did you code it because I was asking for one like this?
    Kyle Jorgensen
    Programmer/Analyst
    WoodmenLife
    Veteran Member
    (308 points)
    Veteran Member
    Posts:114


    Send Message:

    --
    10/18/2013 9:54 AM
    It's one we use.
    Thibaud Lopez Schneider
    Technical Consultant
    Private
    Advanced Member
    (74 points)
    Advanced Member
    Posts:30


    Send Message:

    --
    08/13/2014 5:48 PM
    Have you tried toLocaleString? https://developer.mozilla.org/en-US...caleString

    (1122334455.67890).toLocaleString("en-US", {style:"currency", currency:"USD", maximumFractionDigits: 2}) ==> "$1,122,334,455.68"
    GeoffTSJY
    HRIS Applications Developer
    Private
    Basic Member
    (48 points)
    Basic Member
    Posts:16


    Send Message:

    --
    08/04/2015 6:56 PM
    This is more of a work in progress. But I use this solution to fill in the gaps with processflows email functionality:

    First I build an XML object for an email structure. I use the same template. There is actually more to it than this. If anyone wants to use it I'll give the missing pieces. Most of the missing pieces you can probably figure out pretty easy.

    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...


    Remember, this is something I just whipped up. I'll be refining it over time.

            //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
            <address> elements into the to, cc, bcc fields
            <emailbuilder>
            <subject>
            </subject>
            <prod>
            <to>
            </to>
            <cc>
            </cc>
            <bcc>
            </bcc>
            </prod>
            <test>
            <to>
            </to>
            <cc>
            </cc>
            <bcc>
            </bcc>
            <subjectprefix>xx~! </subjectprefix>
            </test>
            <alerts>
            <paragraph>Please do not reply to this email. This is an automatic notification generated by ProcessFlow</paragraph>
            </alerts>
            </emailbuilder>
            );
            //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<em> + ", "
            }
            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<em>.name().toString()) {
            case "paragraph":
            output += Paragraph(tmp<em>);
            break;
            case "button":
            output += Button(tmp<em>.text, tmp<em>.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 += "
            <p style="margin-bottom: 1em; font-size: 14px; font-family: Verdana, Arial, Helvetica, sans-serif;" +="COLOR:#2f2f2f;MARGIN-TOP:0;LINE-HEIGHT:1.3;TEXT-ALIGN:justify;BACKGROUND-COLOR:transparent align=left>" button="(" label="inLabel;" url="inURL;" xmlns:w="\'urn:schemas-microsoft-com:office:word\'';" arcsize="\'5%\'" strokecolor="\'#EB7035\'" fillcolor="\'#EB7035\'">";
            output += "<w:anchorlock>";
            output += "</w:anchorlock></p>
            <center style="font-family: Helvetica;">";
            output += inLabel;
            output += "</center>";
            output += "";
            output += "<\![endif]-->";
            output += "<\!--[if !mso]><v:roundrect xmlns:v="\'urn:schemas-microsoft-com:vml\'" xmlns:w="\'urn:schemas-microsoft-com:office:word\'';" output+="<div style=TEXT-ALIGN:center;line-height:3>" +="<a href=\" style="border: 1px;">";
            output += inLabel;
            output += "";
            output+="";
            output += "<\![endif]-->";
            return output;
            }
            );
            // DEMO TO USE THIS
            // - First add the addresses
            emailBuilder.prod.to.appendChild(
            <address>
            {approverList.primary.person.(id.ein ==approverList.current.ein).contact.email.toString()}
            </address>
            );
            emailBuilder.test.to.appendChild(
            <address>
            {variableWithMyEmail}
            </address>
            );
            // - next add the subject and body
            emailBuilder.subject = tmpCurrent.name.first + " Position Approval Action Needed";
            emailBuilder.body.prependChild(
            <paragraph>Dear {tmpCurrent.name.first.text()}, please check your LTM inbasket for action.</paragraph>
            );
            emailBuilder.body.appendChild(
            <paragraph>Some more body text.</paragraph>
            );
            emailBuilder.body.appendChild(
            <button>
            <text>Click Me</text><url>www.google.com</url>
            </button>
            );
            //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.
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <title>MailStyler - New</title>
            &#60;&#115;&#116;&#121;&#108;&#101;&#32;&#116;&#121;&#112;&#101;&#61;&#34;&#116;&#101;&#120;&#116;&#47;&#99;&#115;&#115;&#34;&#62;
                .mainTable,
                body {
                height: 100%!important;
                width: 100%!important;
                margin: 0;
                padding: 0
                }
                a img,
                img {
                border: 0;
                outline: 0;
                text-decoration: none
                }
                .imageFix {
                display: block
                }
                table,
                td {
                border-collapse: collapse;
                mso-table-lspace: 0;
                mso-table-rspace: 0
                }
                p {
                margin: 0;
                padding: 0;
                margin-bottom: 0
                }
                .ReadMsgBody {
                width: 100%
                }
                .ExternalClass {
                width: 100%
                }
                .ExternalClass,
                .ExternalClass div,
                .ExternalClass font,
                .ExternalClass p,
                .ExternalClass span,
                .ExternalClass td {
                line-height: 100%
                }
                img {
                -ms-interpolation-mode: bicubic
                }
                a,
                blockquote,
                body,
                li,
                p,
                table,
                td {
                -ms-text-size-adjust: 100%;
                -webkit-text-size-adjust: 100%
                }
                .button {
                height: 100%;
                width: 30%;
                background-color: orange;
                margin: 0 auto;
                font-size: medium;
                font-weight: 700
                }
            &#60;&#47;&#115;&#116;&#121;&#108;&#101;&#62;
            <table class="mainTable" cellspacing="0" cellpadding="0" width="100%" style="background-color: #e0e1e0;">
                <tbody>
                    <tr>
                        <td style="font-size: 0px; height: 20px; line-height: 0;">&nbsp;</td>
                    </tr>
                    <tr>
                        <td valign="top">
                        <table style="width: 600px; margin: 0px auto;" cellspacing="0" cellpadding="0" width="600" align="center" border="0">
                            <tbody>
                                <tr>
                                    <td style="border-top-color: transparent; border-width: 3px medium; border-style: solid none; border-bottom-color: transparent; padding: 4px; background-color: #f7f7f8;">
                                    <table style="width: 100%;" cellspacing="0" cellpadding="0" align="left">
                                        <tbody>
                                            <tr style="height: 10px;">
                                                <td style="border: medium none; width: 1%; vertical-align: top; padding: 5px 4px; text-align: center; background-color: #f7f7f8;"></td>
                                                <td style="border: medium none; width: 99%; vertical-align: middle; padding: 5px 4px 1px; text-align: center; background-color: #f7f7f8;">
                                                <p style="margin-bottom: 1em; font-size: 18px; font-family: Verdana, Arial, Helvetica, sans-serif; color: #909091; margin-top: 0px; line-height: 1.3; text-align: left; background-color: transparent;"><strong>xxx Department of xxx</strong></p>
                                                <p style="margin-bottom: 1em; font-size: 14px; font-family: Verdana, Arial, Helvetica, sans-serif; color: #909091; margin-top: 0px; line-height: normal; text-align: left; background-color: transparent;">xxx xxx Information Systems ()</p>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="border-top-color: transparent; border-width: 3px medium; border-style: solid none; border-bottom-color: transparent; padding: 4px; background-color: #f7f7f8;">
                                    <table style="width: 100%;" cellspacing="0" cellpadding="0" align="left">
                                        <tbody>
                                            <tr style="height: 1px;">
                                                <td style="border: medium none; width: 100%; vertical-align: middle; padding: 1px; text-align: center; background-color: #f7f7f8;">
                                                <table style="margin-bottom: 0px; margin-top: 0px;" width="100%" border="0">
                                                    <tbody>
                                                        <tr>
                                                            <td style="font-size: 1px; border-top-color: #999999; border-width: 1px medium medium; border-style: solid none none; height: 1px; padding-bottom: 0px; padding-top: 0px; line-height: 1px; background: none 0px 0px repeat scroll transparent;">&nbsp;</td>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="border-top-color: transparent; border-width: 3px medium; border-style: solid none; border-bottom-color: transparent; padding: 4px; background-color: #f7f7f8;">
                                    <table style="width: 100%;" cellspacing="0" cellpadding="0" align="left">
                                        <tbody>
                                            <tr style="height: 20px;">
                                                <td style="border: medium none; width: 100%; vertical-align: top; padding: 1px 4px 4px; text-align: center; background-color: #f7f7f8;">
                                                <p style="margin-bottom: 1em; font-size: 18px; font-family: Verdana, Arial, Helvetica, sans-serif; color: #2c7081; margin-top: 0px; line-height: 1.3; text-align: left; background-color: transparent;"><strong>Dear ,</strong>
                                                </p>
                                                <!--sendEmailContent(emailBuilder)-->
                                                </td>
                                            </tr>
                                            <tr style="height: 20px;">
                                                <td style="border: medium none; width: 100%; vertical-align: top; padding: 1px 4px 4px; text-align: center; background-color: yellow;">
                                                <!--sendEmailAlerts(emailBuilder)-->
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="border: medium none; padding: 1px 4px; background-color: transparent;">
                                    <table style="width: 100%;" cellspacing="0" cellpadding="0" align="left">
                                        <tbody>
                                            <tr style="height: 10px;">
                                                <td style="border: medium none; width: 100%; vertical-align: top; padding: 1px 4px; text-align: center; background-color: transparent;">
                                                <p style="margin-bottom: 1em; font-size: 10px; font-family: Arial, Helvetica, sans-serif; color: #909091; margin-top: 0px; line-height: normal; text-align: left; background-color: transparent;">The following is for xxxx use only:</p>
                                                <ul style="margin-bottom: 1em; font-size: 10px; font-family: Arial, Helvetica, sans-serif; color: #909091; margin-top: 0px; line-height: normal; text-align: left; background-color: transparent;">
                                                    <li style="text-align: left;">Workunit:
                                                    <!--oWorkUnit-->
                                                    </li>
                                                    <li style="text-align: left;">ProductLine:
                                                    <!--appProdline-->
                                                    </li>
                                                    <li style="text-align: left;">Host:
                                                    <!--host-->
                                                    </li>
                                                </ul>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                    </tr>
                    <tr>
                        <td style="font-size: 0px; height: 8px; line-height: 0;">&nbsp;</td>
                    </tr>
                </tbody>
            </table>
            
    GeoffTSJY
    HRIS Applications Developer
    Private
    Basic Member
    (48 points)
    Basic Member
    Posts:16


    Send Message:

    --
    08/04/2015 7:08 PM

    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...

     

     

    Joan Herzfeldt
    System Analyst
    Genesis Health System
    Veteran Member
    (137 points)
    Veteran Member
    Posts:51


    Send Message:

    --
    08/16/2016 8:04 AM

    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

    You are not authorized to post a reply.