How to base an Email Trigger or Action on a calculation from responses in two different blocks... | XM Community
Skip to main content
... without losing Back button navigation within the survey?



I have a survey where I need to perform a math operation using the numeric values from questions in two different blocks, in order to determine whether or not to send an email alert. The result of the math operation determines whether or not the respondent meets a threshold, and if not, then the email alert (via an Email Trigger or an Action) is sent to a staff member upon submission of the survey.



I'm using Embedded Data in the Survey Flow and "setEmbeddedData" in Javascript to store the value of the operation. It works if the Embedded Data value is assigned in the middle of the survey, but the catch is that I can't put the Embedded Data element by the Blocks where the questions are located in the Survey Flow or at the end of the survey, because then I would lose the Back button at that point in the survey, and backward navigation is a requirement for this survey.



I've tried assigning the variable for the result of the operation in the Embedded Data at the very beginning of the Survey Flow, but it doesn't compute or get assigned when the operation occurs in later blocks.



Is there a creative workaround to this limitation or an obvious solution I'm missing? Thanks in advance for any insight or suggestions.
Hello @MatthewM ,



You need to do math operation and set embedded data in the JS itself once you have all the data for calculation ready.
Thanks for your reply @Sashi. I guess I didn't state it specifically above, but yes, I've done that too. But as I understand it, when you set embedded data in Javscript you also have to have already created it in the Survey Flow too; I've read that the two have to go hand-in-hand. Or is it possible to set embedded data in Javascript without creating the variable name in an Embedded Data object the Survey Flow?
> @MatthewM said:

> Thanks for your reply @Sashi. I guess I didn't state it specifically above, but yes, I've done that too. But as I understand it, when you set embedded data in Javscript you also have to have already created it in the Survey Flow too; I've read that the two have to go hand-in-hand. Or is it possible to set embedded data in Javascript without creating the variable name in an Embedded Data object the Survey Flow?



You are right, declare the embedded data at the very start of the survey flow
OK, thanks for confirming. I have it working now in my simplified test survey. I had it set up similarly in the working copy of the survey but maybe it failed because the survey had inherited page transitions enabled in the original version from a previous year. I'll keep my fingers crossed that I'll get it to work in this year's final version of the survey.

Leave a Reply