Force reassign of variable values

 9 Replies
 1 Subscribed to this topic
 52 Subscribed to this forum
Sort:
Author
Messages
Joan Herzfeldt
Veteran Member
Posts: 74
Veteran Member
    I have a variable set up in Start (vEmailForm) that uses other variables that are currently blank (vAction, vPerson).  Later in the flow I assign values to these variables (vAction, vPerson) and then use the vEmailForm variable.  Of course the vEmailForm variable has the blank values for  vAction, vPerson.  Is there a way to force the vEmailForm variable to look at the new value of these variables?  perhaps a JavaScript expression or something?   WITHOUT having to actually declare the vEmailForm variable at the same time as the other variables.

    Here is the reason: I have to use this email 6 different times in my flow.  I'd like to have one place to modify the basic form of the email, so when changes are needed I don't have to make changes in six different places.  Suggestions?

    Bob Canham
    Veteran Member
    Posts: 217
    Veteran Member
      Hi Joan,

      The variable assignments are static at the time of the assignment. So when you set your vEmiailForm to contain vAction and vPerson, it sets it to the current values of vAction and vPerson and then forgets about them. If you want to have it contain those values, you need to do the variable assignment after you have those variables. Once you do that, the value will stick for the rest of the flow.
      Joan Herzfeldt
      Veteran Member
      Posts: 74
      Veteran Member

        Hi Bob - 

        Thanks.. I know that's how I'm supposed to code/assign variables, but then I still have to make the same changes to 6 different location, so what's the point in creating variables for the other values (contained in the email) as opposed to using the values themselves. Is it worth the extra coding??

        except.... I could make the requested change on the first one and be able to copy and paste that into the other 5 without having to update.  I guess the real question is how often are changes going to be requested?  Which in the beginning I think often, then it will settle down.

         

        Bob Canham
        Veteran Member
        Posts: 217
        Veteran Member
          are you modifying the value of your vEmailForm, vAction, or vPerson later? If so, then yes, you have to do it every time. I usually use the variables this way if I'm going to use the same value over and over. But if you're changing it a bunch, then it may not help so much.
          Joan Herzfeldt
          Veteran Member
          Posts: 74
          Veteran Member

            The vEmailForm is the body of an email that uses the other two variables.  the vEmailForm doesn't change through out the entire flow, but the variables used in the vEmailForm change up to 6 different times.

            Kyle Jorgensen
            Veteran Member
            Posts: 122
            Veteran Member
              I've pondered this question too.
              Here's what I've done to accomplish this scenario.

              Create vEmailForm with the body text of the email. The variables that are in vEmailForm that need to be substituted later in the flow should have a unique format (not the process flow "
              <!--something-->
              " format).

              I use curly brackets to surround my variables within the body of the email.

              When you need to substitute the variable with values you can use the javascript 'replace' method.

              For example, vEmailForm may contain this text template:
              strEmailBody = vEmailForm.replace(/\{fname\}/g, strFirstName);
              strEmailBody = vEmailForm.replace(/\{day_of_week\}/g, strDayOfWeek);


              Now strEmailBody contains all the text from vEmailForm with all the right substituted variable text.
              Kyle Jorgensen
              Veteran Member
              Posts: 122
              Veteran Member
                Wow, that really didn't render correctly.

                I hope it works this time.

                The portion of my last post that starts with "For example...." should say this:

                For example, vEmailForm may contain this text template
                 vEmailForm = "Hello {fname}, I hope you are having a good {day_of_week}!"; 
                Joan Herzfeldt
                Veteran Member
                Posts: 74
                Veteran Member

                  Awesome!  That is exactly what I was looking for. Thanks so much.

                  Kyle Jorgensen
                  Veteran Member
                  Posts: 122
                  Veteran Member
                    One more little change.
                    The part that does the replacing should look like this:
                    strEmailBody =vEmailForm;
                    strEmailBody = strEmailBody.replace(/\{fname\}/g, strFirstName);
                    strEmailBody = strEmailBody.replace(/\{day_of_week\}/g, strDayOfWeek);


                    This new code ensure that vEmailForm never changes and that subsequent replacements happen in the strEmailBody variable only.
                    Kyle Jorgensen
                    Veteran Member
                    Posts: 122
                    Veteran Member
                      You could even go so far as to make the body of the email a stand-alone text file that the flow reads into vEmailForm as one of the first things it does.

                      That way if you need to make changes to the body of the email (that don't involve adding or removing variables) you can do so without having to change the process flow.