<?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>Invalid index when adding an additional value</title><link>https://community.appian.com/discussions/f/data/20889/invalid-index-when-adding-an-additional-value</link><description>Hello everyone, 
 I am building an interface dynamically for a questionnaire based on previous responses (so I can view the previous answers and then edit them if necessary when re-reviewing). The questions are stored in one database, the items being</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Invalid index when adding an additional value</title><link>https://community.appian.com/thread/81401?ContentTypeID=1</link><pubDate>Wed, 05 May 2021 14:29:10 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b9c96bd1-4327-48f4-bc40-5cd5af6ed27e</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;I&amp;#39;m not sure I see anything at line 119 in your original code box that seems problematic to me.&amp;nbsp; I was thinking more about your local variable definition at line 77 (which i notice you don&amp;#39;t end up using anywhere subsequently in the form).&amp;nbsp; Basically your a!forEach() statement should be constructing an array of answers that correspond to your existing questions (the forEach statement already loops over the questions in about the same way that it probably ends up needing).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Invalid index when adding an additional value</title><link>https://community.appian.com/thread/81392?ContentTypeID=1</link><pubDate>Wed, 05 May 2021 11:44:53 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:71514b44-7682-4479-a276-89591a6d9733</guid><dc:creator>robinh0003</dc:creator><description>&lt;p&gt;I think the suggestion to &amp;quot;declare a blank / default array entry of the &amp;quot;response&amp;quot; type&amp;quot; is the root of my issue, but I&amp;#39;m not sure how to accomplish this. Do you know of any documentation or sample code you could point me to that I could try adapting to our environment?&lt;/p&gt;
&lt;p&gt;*Edit: Specifically, I&amp;#39;m looking at line 119 above as the possible culprit. Would you agree?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Invalid index when adding an additional value</title><link>https://community.appian.com/thread/81344?ContentTypeID=1</link><pubDate>Tue, 04 May 2021 13:52:53 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:ffdc9928-b4d4-4704-81eb-0ae884a05417</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;I believe the solution requires that you do some initial formatting on the &amp;quot;answers&amp;quot; array - either prior to your user input task, or (maybe preferably) in your local variable definitions.&amp;nbsp; In the latter case, you&amp;#39;d want to save directly into the value of your local variable response array, rather than saving directly into the rule input as you&amp;#39;re currently attempting; then upon click of the &amp;quot;submit&amp;quot; button, you&amp;#39;d push the value of the local variable back into the rule input.&lt;/p&gt;
&lt;p&gt;In either case the logic would be simply something like this: loop through the list of questions; look in the existing responses array for the current index.&amp;nbsp; If the index exists, keep the response at that index.&amp;nbsp; Otherwise if the index doesn&amp;#39;t exist (i.e. you have 15 questions but only 14 extant responses, and we&amp;#39;re now at index 15 of the questions array), declare a blank / default array entry of the &amp;quot;response&amp;quot; type.&amp;nbsp; Then when you try direct reference to a &amp;quot;newReferenceResponse&amp;quot; entry (i.e. &amp;quot;&lt;em&gt;ri!newReferenceResponse[fv!index]&lt;/em&gt;&amp;quot;), it should no longer break.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Invalid index when adding an additional value</title><link>https://community.appian.com/thread/81342?ContentTypeID=1</link><pubDate>Tue, 04 May 2021 11:16:03 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:113fc8c0-b661-4138-aad2-afbe89affb04</guid><dc:creator>robinh0003</dc:creator><description>&lt;p&gt;Thanks, Mike.&lt;/p&gt;
&lt;p&gt;I suppose that information would have been helpful. The questions aren&amp;#39;t added in Appian (I don&amp;#39;t have an interface built for it yet) so they are added manually to the database. Hopefully I can explain this a bit better, but the way the process works is:&lt;/p&gt;
&lt;p&gt;1. An asset is entered and the questions answered as applicable to that asset (static questions, mostly Yes/No)&lt;/p&gt;
&lt;p&gt;2. Responses are recorded in another table&lt;/p&gt;
&lt;p&gt;3. When the asset is re-assessed, Appian first puts together the list of questions and responses as they were entered the last time&lt;/p&gt;
&lt;p&gt;4. If nothing has changed I can simply submit the page and keep moving through the workflow. If it has changed, I change the questionnaire to provide the edited information, then submit&lt;/p&gt;
&lt;p&gt;I suspect the issue is between steps 3-4 where the question I added was not included in the previous assessment, but when I inserted responses in the DB it still errored with the same index issue.&lt;/p&gt;
&lt;p&gt;Does that help?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Invalid index when adding an additional value</title><link>https://community.appian.com/thread/81334?ContentTypeID=1</link><pubDate>Mon, 03 May 2021 20:47:04 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:4340f583-7367-487f-b6f2-38b2539bf437</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;You mentioned this error happens when you add a new question/answer, but I don&amp;#39;t see any place in your code where such addition is handled.&amp;nbsp; When doing this addition, are you also adding a corresponding item to the end of the `&lt;em&gt;ri!newreferenceResponse&lt;/em&gt;` array?&amp;nbsp; The error indicates that its length is not matching the length of &lt;em&gt;local!questions&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;I notice that &lt;em&gt;&lt;strong&gt;local!&lt;/strong&gt;newreferenceResponse&lt;/em&gt; *does* appear to be configured to follow the length of &lt;em&gt;local!questions&lt;/em&gt; by local variable &amp;quot;update chaining&amp;quot; as i call it, but of course this is completely separate from &lt;em&gt;&lt;strong&gt;ri!&lt;/strong&gt;newreferenceResponse&lt;/em&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>