<?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>Need to manipulate the array</title><link>https://community.appian.com/discussions/f/rules/38477/need-to-manipulate-the-array</link><description>This a the above data now my requirement is remove null status only for the duplicate name and transfer the test value to the non-null status. Can any one please help me with this.</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Need to manipulate the array</title><link>https://community.appian.com/thread/145145?ContentTypeID=1</link><pubDate>Fri, 07 Feb 2025 13:01:27 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:994f40bc-d4b3-4102-bae2-67ed82fcd4e3</guid><dc:creator>Mathieu Drouin</dc:creator><description>&lt;p&gt;Assuming this is the output you were looking for:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;{
    &amp;quot;name&amp;quot;: &amp;quot;John&amp;quot;,
    &amp;quot;status&amp;quot;: 10,
    &amp;quot;test&amp;quot;: null
},
{
    &amp;quot;name&amp;quot;: &amp;quot;Alice&amp;quot;,
    &amp;quot;status&amp;quot;: 5,
    &amp;quot;test&amp;quot;: null
},
{
    &amp;quot;name&amp;quot;: &amp;quot;Bob&amp;quot;,
    &amp;quot;status&amp;quot;: null,
    &amp;quot;test&amp;quot;: 8
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This will:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Remove any duplicate items with a status of null&lt;/li&gt;
&lt;li&gt;Transfer the test value for any values that have a non-null status&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!data: {
    { name: &amp;quot;John&amp;quot;, status: &amp;quot;Active&amp;quot;, test: 10 },
    { name: &amp;quot;John&amp;quot;, status: null, test: 4 },
    { name: &amp;quot;Alice&amp;quot;, status: &amp;quot;Active&amp;quot;, test: 5 },
    { name: &amp;quot;Alice&amp;quot;, status: null, test: 6 },
    { name: &amp;quot;Bob&amp;quot;, status: null, test: 8 }
  },
  local!cleanData: a!forEach(
    items: local!data,
    expression: a!localVariables(
      local!dataWithoutCurrentItem: remove(local!data, fv!index),
      local!hasDuplicates: count(
        index(
          local!dataWithoutCurrentItem,
          wherecontains(
            fv!item.name,
            local!dataWithoutCurrentItem.name
          )
        )
      ) &amp;gt; 0,
      if(
        and(
          local!hasDuplicates,
          a!isNullOrEmpty(fv!item.status)
        ),
        null,
        if(
          a!isNotNullOrEmpty(fv!item.status),
          a!map(
            name: fv!item.name,
            status: fv!item.test,
            test: null
          ),
          fv!item
        )
      )
    )
  ),
  reject(a!isNullOrEmpty, local!cleanData)
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Need to manipulate the array</title><link>https://community.appian.com/thread/145140?ContentTypeID=1</link><pubDate>Fri, 07 Feb 2025 09:35:42 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:67ba9f2b-9cf8-4667-ae99-bd47e0f59a81</guid><dc:creator>Andrew Hickingbotham</dc:creator><description>&lt;p&gt;I&amp;#39;m not sure how this use case has come about but it appears to me that something has gone wrong to require doing this manipulation. I don&amp;#39;t feel good about the below solution because it relies on too many assumptions and just feels flimsy. Having said that, I hope the below helps.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;I think this is the&amp;nbsp;output you are looking for:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;{
    { name: &amp;quot;John&amp;quot;, status: &amp;quot;Active&amp;quot;, test: 4},
    { name: &amp;quot;Alice&amp;quot;, status: &amp;quot;Active&amp;quot;, test: 6},
    { name: &amp;quot;Bob&amp;quot;, status: null, test: 8}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The code:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!data: {
    { name: &amp;quot;John&amp;quot;, status: &amp;quot;Active&amp;quot;, test: 10 },
    { name: &amp;quot;John&amp;quot;, status: null, test: 4 },
    { name: &amp;quot;Alice&amp;quot;, status: &amp;quot;Active&amp;quot;, test: 5 },
    { name: &amp;quot;Alice&amp;quot;, status: null, test: 6 },
    { name: &amp;quot;Bob&amp;quot;, status: null, test: 8 }
  },
  a!forEach(
    items: local!data,
    expression: a!localVariables(
      local!name: index(
        fv!item,
        &amp;quot;name&amp;quot;,
        {}
      ),
      local!status: index(
        fv!item,
        &amp;quot;status&amp;quot;,
        {}
      ),
      local!indexesWhereNameMatches: where(
        local!name = index(
          local!data,
          &amp;quot;name&amp;quot;,
          {}
        )
      ),
      local!hasDuplicate: length(local!indexesWhereNameMatches) &amp;gt; 1,
      /*Assume only one duplicate is possible*/
      local!duplicateIndex: if(
        local!hasDuplicate,
        difference(
          local!indexesWhereNameMatches,
          fv!index
        ),
        {}
      ),
      /*Assume duplicate will always have null status and therefore to use that test value*/
      local!testValueToUse: if(
        local!hasDuplicate,
        index(
          index(
            index(
              local!data,
              local!duplicateIndex,
              {}
            ),
            &amp;quot;test&amp;quot;,
            {}
          ),
          1,
          {}
        ),
        index(
          fv!item,
          &amp;quot;test&amp;quot;,
          {}
        )
      ),
      local!statusIsNull: a!isNullOrEmpty(local!status),
      local!replaceTestValue: and(
        local!hasDuplicate,
        not(local!statusIsNull)
      ),
      local!removeIndex: and(
        local!statusIsNull,
        local!hasDuplicate
      ),
      local!allDetailsNeeded: a!map(
        name: local!name,
        status: local!status,
        hasDuplicate: local!hasDuplicate,
        statusIsNull: local!statusIsNull,
        replaceTestValue: local!replaceTestValue,
        testValueToUse: local!testValueToUse,
        removeIndex: local!removeIndex
      ),
      if(
        local!removeIndex,
        {},
        a!update(
          data: fv!item,
          index: &amp;quot;test&amp;quot;,
          value: local!testValueToUse
        )
      )
    )
  )
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Need to manipulate the array</title><link>https://community.appian.com/thread/145139?ContentTypeID=1</link><pubDate>Fri, 07 Feb 2025 08:27:00 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:6af78770-1e97-4fc8-9cdd-7d20c8c830b8</guid><dc:creator>JayaPrakash Ravipati</dc:creator><description>&lt;p&gt;hi,&lt;/p&gt;
&lt;p&gt;So you want to remove the duplicate null with null status right. Hope the code will help&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!data: {
    { name: &amp;quot;John&amp;quot;, status: &amp;quot;Active&amp;quot;, test: 10 },
    { name: &amp;quot;John&amp;quot;, status: null, test: 4 },
    { name: &amp;quot;Kiran&amp;quot;,status: null, test: 10},
    { name: &amp;quot;Kiran&amp;quot;,status: &amp;quot;Active&amp;quot;, test: 10},
    { name: &amp;quot;Alice&amp;quot;, status: &amp;quot;Active&amp;quot;, test: 5 },
    { name: &amp;quot;Alice&amp;quot;, status: null, test: 6 },
    { name: &amp;quot;Bob&amp;quot;, status: null, test: 8 }
  },
  local!uniqueNames:union(index(local!data,&amp;quot;name&amp;quot;,null),index(local!data,&amp;quot;name&amp;quot;,null)),
  local!DuplicateUsers:reject(fn!isnull,a!forEach(
    items: local!uniqueNames,
    expression: if(
      count(wherecontains(touniformstring(fv!item),touniformstring(index(local!data,&amp;quot;name&amp;quot;,null))))&amp;gt;1,
      fv!item,
      null()
    )
  )),
  local!duplicateUserIndexes:index(local!data,wherecontains(
    touniformstring(local!DuplicateUsers),
    touniformstring(index(local!data,&amp;quot;name&amp;quot;,null))
  ),null),
  reject(fn!isnull,a!forEach(
    items: local!duplicateUserIndexes,
    expression: if(
      touniformstring(index(fv!item,&amp;quot;status&amp;quot;,null))=touniformstring(null),
      null,
      fv!item
    )
  ))
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>