<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Saving Multiple Page Survey Answers as a JSON Object</title><link>https://community.appian.com/discussions/f/data/21738/saving-multiple-page-survey-answers-as-a-json-object</link><description>Hi, 
 I am trying to save the user answers of multiple page survey interface in one local variable as a json object to save it to the database. I have rendered these multilevel questions from part of the json object like that: 
 { &amp;quot;sections&amp;quot;: [{ &amp;quot;sectionname</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Saving Multiple Page Survey Answers as a JSON Object</title><link>https://community.appian.com/thread/85074?ContentTypeID=1</link><pubDate>Fri, 27 Aug 2021 15:38:41 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:e061c59c-83b6-41d1-b05d-a7f4540e0afb</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;At a high level I&amp;#39;m only referring to code you&amp;#39;ve already pasted previously in this post not within code boxes.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As per your issue: I looked through the code briefly and as of yet I don&amp;#39;t have any specific suggestions other than my normal advice, which is, start with a simple-but-working version, and add complexity one step at a time making sure each addition still works.&lt;/p&gt;
&lt;p&gt;If you&amp;#39;d be willing to edit your original post to include the same code you posted originally, but moved into a code box and with restored indentation, I&amp;#39;ll try to take a closer look.&amp;nbsp; (Restoring indentation should be as easy as opening a blank Expression Rule editor and pasting the code there, then re-copying the result).&amp;nbsp; As an aside: when posting Appian Expression/SAIL code I often select the &amp;quot;JAVA&amp;quot; language option in the Code Box settings as it adds context highlighting that seems generally compatible with Appian code (though I do wish they&amp;#39;d add an Appian-specific option...)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving Multiple Page Survey Answers as a JSON Object</title><link>https://community.appian.com/thread/85073?ContentTypeID=1</link><pubDate>Fri, 27 Aug 2021 15:32:23 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:6a9f3ad0-0a38-4903-aa29-87ec895adb03</guid><dc:creator>ahmedk927042</dc:creator><description>&lt;p&gt;I have more than 2000 lines of code so could you please let me know which part would you like me to copy here?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving Multiple Page Survey Answers as a JSON Object</title><link>https://community.appian.com/thread/85071?ContentTypeID=1</link><pubDate>Fri, 27 Aug 2021 14:57:26 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:2f32ade9-1074-4074-8f27-db11b63c93b2</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;To clarify, if you copy/paste indented code straight from Appian into a code box, indentation will be preserved as well.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving Multiple Page Survey Answers as a JSON Object</title><link>https://community.appian.com/thread/85070?ContentTypeID=1</link><pubDate>Fri, 27 Aug 2021 14:51:49 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:8d407f2b-9758-4266-a09f-3e0e50af9cd2</guid><dc:creator>ahmedk927042</dc:creator><description>&lt;p&gt;Hi Mike! Thank you for your response! I am adding here the same code i added above to save the value for each response.&lt;pre class="ui-code" data-mode="text"&gt;a!forEach(
items: local!questions,
expression: {
/*the start of the questions types*/
if(
fv!item.responsetype = &amp;quot;text&amp;quot;,
a!textField(
value: fv!item.answertext,
saveInto: {
fv!item.answertext,
}
),
)})&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving Multiple Page Survey Answers as a JSON Object</title><link>https://community.appian.com/thread/85069?ContentTypeID=1</link><pubDate>Fri, 27 Aug 2021 14:43:59 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5b51ea7f-0897-46cd-8d8c-32d708a6ed0b</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;Tangentially, this is a **lot** of code to paste into a post in plaintext.&amp;nbsp; You should probably use a Code Box, which makes things like this 100x readable through length limiting, monospaced font, and preservation of indentation/etc.&lt;br /&gt;&lt;img src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/16/pastedimage1630075435584v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving Multiple Page Survey Answers as a JSON Object</title><link>https://community.appian.com/thread/85068?ContentTypeID=1</link><pubDate>Fri, 27 Aug 2021 14:22:18 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a56d584e-6a43-4658-9109-5494618ac9cf</guid><dc:creator>ahmedk927042</dc:creator><description>&lt;p&gt;I already read successfully the json object using those functions as the code below:&lt;/p&gt;
&lt;p&gt;local!roots: a!fromJson(&lt;br /&gt; a!jsonPath(&lt;br /&gt; rule!PCEMS_querySurveyJSON(),&lt;br /&gt; &amp;quot;['sections'][*][?(@.sectionparent=='root')]&amp;quot;&lt;br /&gt; )&lt;br /&gt; )&lt;/p&gt;
&lt;p&gt;and i am looping on the objects successfully and everything renders fine. the issue here i need to save the user responses for the survey questions in one local variable. i am able to save just each page responses through this code:&lt;/p&gt;
&lt;p&gt;&lt;span&gt;a!forEach(&lt;/span&gt;&lt;br /&gt;&lt;span&gt;items: local!questions,&lt;/span&gt;&lt;br /&gt;&lt;span&gt;expression: {&lt;/span&gt;&lt;br /&gt;&lt;span&gt;/*the start of the questions types*/&lt;/span&gt;&lt;br /&gt;&lt;span&gt;if(&lt;/span&gt;&lt;br /&gt;&lt;span&gt;fv!item.responsetype = &amp;quot;text&amp;quot;,&lt;/span&gt;&lt;br /&gt;&lt;span&gt;a!textField(&lt;/span&gt;&lt;br /&gt;&lt;span&gt;value: fv!item.answertext,&lt;/span&gt;&lt;br /&gt;&lt;span&gt;saveInto: {&lt;/span&gt;&lt;br /&gt;&lt;span&gt;fv!item.answertext,&lt;/span&gt;&lt;br /&gt;&lt;span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span&gt;),&lt;/span&gt;&lt;br /&gt;&lt;span&gt;)})&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;but when i move to another section, this local!questions will be refreshed with the new questions of that subsection page. so i need to have a local variable which has all of the answers and if the user update the value it should be updated in there also.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving Multiple Page Survey Answers as a JSON Object</title><link>https://community.appian.com/thread/85065?ContentTypeID=1</link><pubDate>Fri, 27 Aug 2021 13:59:09 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:818e39c9-0a9c-41c1-9a99-67bacbc59e9b</guid><dc:creator>Danny Verb</dc:creator><description>&lt;p&gt;You can use the sql type TEXT as your column and store the JSON in there. I know you say you&amp;#39;re looping through the JSON. I&amp;#39;m not sure what you mean but the simplest way to handle JSON in Appian is to use a map/dictionary for everything and then to use the a!toJSON() and a!fromJSON() functions&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving Multiple Page Survey Answers as a JSON Object</title><link>https://community.appian.com/thread/85064?ContentTypeID=1</link><pubDate>Fri, 27 Aug 2021 13:49:45 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:8bc9d082-00b2-4860-91c4-01993028ea67</guid><dc:creator>ahmedk927042</dc:creator><description>&lt;p&gt;Hi Danny,&lt;/p&gt;
&lt;p&gt;Thank you for your response! The survey has a hierarchy structure like in the Json above like (children and parents relationship). but any way i already built it by nested loop on the json. but the challenge&amp;nbsp;here how i am going to map all of the answers for all of the subsections of the survey in one place. till now i can map each page answers with a local variable but when i move to another subsection, the local variable will have a new value of the new page questions. I am trying to collect all of the answers in one local variable to save it in&amp;nbsp;a database table as a json object. any thoughts&amp;nbsp;to achieve that?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving Multiple Page Survey Answers as a JSON Object</title><link>https://community.appian.com/thread/85062?ContentTypeID=1</link><pubDate>Fri, 27 Aug 2021 13:40:59 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:03705caf-6ae8-439d-8497-75e55bce6fd4</guid><dc:creator>Danny Verb</dc:creator><description>&lt;p&gt;When you say &amp;#39;multiple pages&amp;#39; are you referring to a wizard on the same Interface or multiple user inputs tasks? If everything is on the same interface, then you can abstract your dictionary a little more by having a map&lt;br /&gt;a!map(&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;pageOne: local!jsonOne,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;pageTwo: local!jsonTwo&lt;/p&gt;
&lt;p&gt;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>