Adobe Campaign Survey - Save Variables into Database

I had a scenario where I need to show some questions depending on the answers of a previous question.
For example, the below test scenario
So I created the Archive field for all the questions including the Radio button and Drop down one which will be used for the dynamic criteria. I had setup the visibility of the field using the Archive Field. But while previewing I realized that the questions are getting shown or hidden depending on selection (example below).

So I created two new variables for the survey with names as How_was_your_last_hopital_visit and Was_your_out_of_pocket_expenses_over_budget_.
Then changed the visibility criteria to use the variables. Now it is working perfectly. But when I saved the survey, it doesn't save the data of those variables. But I need those selections as well.
So I added a javascript task before the Storage activity and set the tables fields from the variables so that when it is in the storage activity, it column value is populated from the variable already

Here is the js activity code
var How_was_your_last_hopital_visit = ctx.vars.How_was_your_last_hopital_visit;
var Was_your_out_of_pocket_expenses_over_budget_ = ctx.vars.Was_your_out_of_pocket_expenses_over_budget_;

logInfo("How_was_your_last_hopital_visit:" + How_was_your_last_hopital_visit);
logInfo("Was_your_out_of_pocket_expenses_over_budget_:" + Was_your_out_of_pocket_expenses_over_budget_);

ctx.webAppLogRecipientData.How_was_your_last_hopital_visit = How_was_your_last_hopital_visit;
ctx.webAppLogRecipientData.Was_your_out_of_pocket_expenses_over_budget_ = Was_your_out_of_pocket_expenses_over_budget_;

Note: ctx.webAppLogRecipientData part will be as per the table you selected into your survey. Enable the debug in preview to get the actual name of the table

And here is the workflow

So, here is the summary
  • Create the variable in survey properties
  • Use the variable inside workflow
  • Create Archive field to store the variables
  • Add a Script activity before Storage Activity 
  • Update the ctx.surveyResponsetableName.ArchiveField=ctx.vars.VariableName

Comments

Popular posts from this blog

Avoid Proxy for HttpClientRequest - IOB-090007 Network error (send(), errno=10054: an existing connection was forcibly closed by the remote host

Adobe Campaign: Call Java Script from Input Form

Broadlog Resequencing in Adobe Campaign Classic