<?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>Sub-process input variable: Cannot index from an array using tp[instanceIndex]</title><link>https://community.appian.com/discussions/f/general/28029/sub-process-input-variable-cannot-index-from-an-array-using-tp-instanceindex</link><description>Hi everyone, I&amp;#39;m having this issue where I&amp;#39;m trying to index a date and time array using the index of caseID from another array with same order. Below are the process variables and the code that I wrote: 
 
 
 
 allCases 
 Number (Integer) 
 
 3,061,158;</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Sub-process input variable: Cannot index from an array using tp[instanceIndex]</title><link>https://community.appian.com/thread/109128?ContentTypeID=1</link><pubDate>Thu, 09 Mar 2023 16:25:29 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:39111cdd-a93b-42a9-8370-b4b2dac1cc4e</guid><dc:creator>Naresh</dc:creator><description>&lt;p&gt;If subprocess is not necessary in your use case you can use start process which allow you to use tp!instanceindex&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sub-process input variable: Cannot index from an array using tp[instanceIndex]</title><link>https://community.appian.com/thread/109125?ContentTypeID=1</link><pubDate>Thu, 09 Mar 2023 16:02:02 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:ce4710f5-a905-441b-b9a3-7a855824fdaf</guid><dc:creator>Komal Jain</dc:creator><description>&lt;p&gt;Thank You Mike. I create the CDT so that we are inline with proper data structure , if further needed it can be extend and easily maintained through CDT . Thank for you suggestion on using Map&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sub-process input variable: Cannot index from an array using tp[instanceIndex]</title><link>https://community.appian.com/thread/109124?ContentTypeID=1</link><pubDate>Thu, 09 Mar 2023 15:55:51 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1fecc7fb-9d7d-41dd-8c66-d943dc79c2e5</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;FYI, this is the sort of solution I proposed above, except now with the ability to add PVs of the type &amp;quot;Map&amp;quot;, there&amp;#39;s no need to create a custom CDT just to hold the values in question as you seem to have done here with pv!allData and the &amp;quot;KJA_caseswithtask&amp;quot; data type.&amp;nbsp; We can just create a Map (multiple) PV and assemble an array of Map objects within the a!forEach loop, and the process handles it.&lt;/p&gt;
&lt;p&gt;Edit: but i&amp;#39;m giving you a well-earned upvote anyway due to your apparently extensive work setting up a live example, and gathering of screenshots - well done &lt;span class="emoticon" data-url="https://community.appian.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sub-process input variable: Cannot index from an array using tp[instanceIndex]</title><link>https://community.appian.com/thread/109121?ContentTypeID=1</link><pubDate>Thu, 09 Mar 2023 15:49:35 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:13a9f5a7-be56-4bdc-97a1-8bfd07741b09</guid><dc:creator>Komal Jain</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Please try this to solve your MNI&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/11/pastedimage1678376586612v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;I am setting some value in caseid, casewithtask and date in first script task&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/11/pastedimage1678376646734v2.png" /&gt;&lt;img alt=" " src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/11/pastedimage1678376664574v3.png" /&gt;&lt;img alt=" " src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/11/pastedimage1678376679412v4.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;In Second script task i mapped the case id and date into a CDT&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/11/pastedimage1678376717573v5.png" /&gt;&lt;img alt=" " src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/11/pastedimage1678376736986v6.png" /&gt;&lt;img alt=" " src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/11/pastedimage1678376750018v7.png" /&gt;&lt;img alt=" " src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/11/pastedimage1678376765937v8.png" /&gt;&lt;/p&gt;
&lt;p&gt;In Sub Process I am using the mapped CDT for MNI&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/11/pastedimage1678376792792v9.png" /&gt;&lt;img alt=" " src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/11/pastedimage1678376872453v11.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Here is the data from sub process instance&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/11/pastedimage1678377012374v13.png" /&gt;&lt;img alt=" " src="/resized-image/__size/320x240/__key/communityserver-discussions-components-files/11/pastedimage1678377026074v14.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sub-process input variable: Cannot index from an array using tp[instanceIndex]</title><link>https://community.appian.com/thread/109120?ContentTypeID=1</link><pubDate>Thu, 09 Mar 2023 15:43:00 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a2d3e903-e954-4f6f-ba6d-95abaa2d9c03</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;I second Stefan&amp;#39;s suggested approach.&amp;nbsp; Add a single script task node right before your subprocess call, and have it output to a new PV of type Array of Map.&lt;/p&gt;
&lt;p&gt;The script task would have a single output entry wherein you reassemble essentially the same code you were trying to pass directly into your subprocess inputs:&lt;br /&gt;&lt;pre class="ui-code" data-mode="java"&gt;a!forEach(
  pv!casesWithTask,
  
  a!map(
    caseId: fv!item,
    updatedTime: index(
      pv!updatedDateTime,
      whereContains(
        fv!item,
        pv!allCases
      ),
      now()
    )
  )
)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You would then hopefully have a PV set to the proper value(s) for your input array, which you can verify the correct values of.&amp;nbsp; And then for your subprocess inputs, you&amp;#39;d simply set the MNI to reference your new Map PV, and the inputs would be &lt;em&gt;pv!myNewMap[tp!instanceIndex].caseId&lt;/em&gt;, and &lt;em&gt;pv!myNewMap[tp!instanceIndex].updatedTime&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Also (and somewhat confusingly), you might not even need the &lt;em&gt;tp!instanceIndex&lt;/em&gt; reference when referring to the specific PV set as the MNI identifier - Appian seems to use some sort of fuzzy logic to automatically pull the &amp;quot;current index&amp;quot; at least when not otherwise overridden.&amp;nbsp; I haven&amp;#39;t tested this extensively recently but it seems to somehow work both ways in some instances.&amp;nbsp; If anyone knows in any more detail how this works exactly, I wouldn&amp;#39;t mind a better description myself, hah.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sub-process input variable: Cannot index from an array using tp[instanceIndex]</title><link>https://community.appian.com/thread/109080?ContentTypeID=1</link><pubDate>Thu, 09 Mar 2023 09:48:26 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:bbcd9af7-824e-4f43-9ce4-5a5234647896</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;If you need to just pass a single value, then go with this and skip the&amp;nbsp;map. I just wanted to give you an idea of how to approach that situation in a different way.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sub-process input variable: Cannot index from an array using tp[instanceIndex]</title><link>https://community.appian.com/thread/109079?ContentTypeID=1</link><pubDate>Thu, 09 Mar 2023 09:33:02 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:316c9d72-26f4-4b4e-a2b3-ab18b2c30f79</guid><dc:creator>Furman</dc:creator><description>&lt;p&gt;how many sub processes are triggered? is number correct? Is casesId passed right to sub process? If yes then there is nothing wrong with tpinstanceInded - there is something wrong with if.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sub-process input variable: Cannot index from an array using tp[instanceIndex]</title><link>https://community.appian.com/thread/109078?ContentTypeID=1</link><pubDate>Thu, 09 Mar 2023 09:03:30 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:7359e252-2048-4b10-b9d9-f3f96fca98e7</guid><dc:creator>mollyn126</dc:creator><description>&lt;p&gt;The input variable type for sub-process is Date and Time, so when I index from Map, the value cannot be passed into sub-process due to data type mismatch...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sub-process input variable: Cannot index from an array using tp[instanceIndex]</title><link>https://community.appian.com/thread/109077?ContentTypeID=1</link><pubDate>Thu, 09 Mar 2023 08:03:28 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b33241f8-12a1-45e4-9e79-2997a4b35837</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;I understand. But almost impossible to debug. Maybe you want to create an expression that creates a list of maps containing the required data that you then pass to your sub processes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sub-process input variable: Cannot index from an array using tp[instanceIndex]</title><link>https://community.appian.com/thread/109076?ContentTypeID=1</link><pubDate>Thu, 09 Mar 2023 08:03:07 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:801e8b1d-aa08-4e5f-bf55-0672f12491ef</guid><dc:creator>mollyn126</dc:creator><description>&lt;p&gt;&lt;span&gt;I created a scriptask and tried&amp;nbsp;index(pv!updatedDateTime,wherecontains(pv![a case ID instead of pv!casesWithTask[tp!instanceindex],pv!allCases),null), this will return me the exact date time at that index. But it does not work with tp!instanceIndex not sure why...&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sub-process input variable: Cannot index from an array using tp[instanceIndex]</title><link>https://community.appian.com/thread/109075?ContentTypeID=1</link><pubDate>Thu, 09 Mar 2023 08:03:00 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:a2a64604-fa92-4786-9672-102fa704bf9c</guid><dc:creator>mollyn126</dc:creator><description>&lt;p&gt;Yes. casesWithTasks and allCases are both integer. updatedDateTime is now Date and Time (multiple values) type.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I created a scriptask and tried&amp;nbsp;index(pv!updatedDateTime,wherecontains(pv![a case ID instead of pv!casesWithTask[tp!instanceindex],pv!allCases),null), this will return me the exact date time at that index. But it does not work with tp!instanceIndex not sure why...&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sub-process input variable: Cannot index from an array using tp[instanceIndex]</title><link>https://community.appian.com/thread/109074?ContentTypeID=1</link><pubDate>Thu, 09 Mar 2023 07:59:43 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:811f4901-e2a6-4cdd-ac70-7008475f255c</guid><dc:creator>mollyn126</dc:creator><description>&lt;p&gt;I want to find datetime for each casesWithTask then pass that value into my sub-process. Not sure if tp!instanceIndex can be used in scriptask?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sub-process input variable: Cannot index from an array using tp[instanceIndex]</title><link>https://community.appian.com/thread/109071?ContentTypeID=1</link><pubDate>Thu, 09 Mar 2023 07:40:09 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:12c1465c-5ed6-48a5-918d-5f0791e84c39</guid><dc:creator>Furman</dc:creator><description>&lt;p&gt;Are casesWithTasks and allCases same type? Is pv!updatedDateTime an array/dictionary? First i will take your where contains and check it manually if it ever return any true for any tpinstanceinex. Then check if index of pv!updatedDatetime return anything if you provide 1 or 2 as second argument.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sub-process input variable: Cannot index from an array using tp[instanceIndex]</title><link>https://community.appian.com/thread/109070?ContentTypeID=1</link><pubDate>Thu, 09 Mar 2023 07:39:39 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:0518d95f-8830-4faf-9784-98d0c2a62117</guid><dc:creator>Stefan Helzle</dc:creator><description>&lt;p&gt;With seeing the data its impossible to say anything. I recommend to not &amp;quot;hide&amp;quot; such logic inside the value assignment, but use a separate script task and store the result in a PV. That make debugging also a lot easier.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>