<?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>Getting data group by field and the latest one</title><link>https://community.appian.com/discussions/f/general/33917/getting-data-group-by-field-and-the-latest-one</link><description>Hi Champs, 
 I need to fetch only unique value from a dictionary with the latest data. Below is the sample of the output 
 
 
 Here you can see color highlighted ones are same value of training name. So instead of 5 dictionary I want only 3 with unique</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Getting data group by field and the latest one</title><link>https://community.appian.com/thread/128712?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2024 07:08:35 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:ffdd71d2-94b4-4217-8041-cd5bb0d3b7d8</guid><dc:creator>Harshmodi</dc:creator><description>&lt;p&gt;Hello&amp;nbsp;&amp;nbsp;,&lt;br /&gt;I think this piece of code can fetch the latest of the duplicate data.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!data: {
    {
      trainigNotes: &amp;quot;testt&amp;quot;,
      trainingDoc: 48195,
      trainingName: &amp;quot;SPPT1&amp;quot;,
      id: 2,
      hcpId: 4
    },
    {
      trainigNotes: &amp;quot;testingDoubtData&amp;quot;,
      trainingDoc: 48196,
      trainingName: &amp;quot;SPPT1&amp;quot;,
      id: 3,
      hcpId: 4
    },
    {
      trainigNotes: &amp;quot;unique&amp;quot;,
      trainingDoc: 132595,
      trainingName: &amp;quot;SPPT5&amp;quot;,
      id: 8509,
      hcpId: 4
    },
    {
      trainigNotes: &amp;quot;cep2&amp;quot;,
      trainingDoc: 132594,
      trainingName: &amp;quot;SPPT2&amp;quot;,
      id: 8510,
      hcpId: 4
    },
    {
      trainigNotes: &amp;quot;cep1&amp;quot;,
      trainingDoc: 132593,
      trainingName: &amp;quot;SPPT2&amp;quot;,
      id: 8511,
      hcpId: 4
    },

  },
  local!trainingNames: index(local!data, &amp;quot;trainingName&amp;quot;, &amp;quot;&amp;quot;),
  local!uniqueNames: union(local!trainingNames, local!trainingNames),
  local!indexes: a!forEach(
    items: local!uniqueNames,
    expression: index(
      wherecontains(
        fv!item,
        touniformstring(index(local!data, &amp;quot;trainingName&amp;quot;, &amp;quot;&amp;quot;))
      ),
      1,
      {}
    )
  ),
  index(local!data, local!indexes, {})
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting data group by field and the latest one</title><link>https://community.appian.com/thread/128691?ContentTypeID=1</link><pubDate>Thu, 01 Feb 2024 14:14:49 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:636a12a2-2098-4cf7-8f29-bae1b913cf25</guid><dc:creator>Konduru Chaitanya</dc:creator><description>&lt;p&gt;Hello &amp;nbsp;&lt;br /&gt;&lt;br /&gt;I hope this is what you have asked. (Sorry for the old reply. Didn&amp;#39;t catch the last part)&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;a!localVariables(
  local!data: a!queryRecordType(
    recordType: &amp;#39;recordType!{813c8d12-c70d-4373-b9d3-bbb60dbb1d56}Employee Detail&amp;#39;,
    fields: {},
    pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 100)
  ).data,
  /*Replace with your rule*/
  local!lastName: a!map(
    lastName: index(
      local!data,
      &amp;#39;recordType!{813c8d12-c70d-4373-b9d3-bbb60dbb1d56}Employee Detail.fields.{c9452bf3-7a5b-4464-bdea-a86ec4c64484}lastname&amp;#39;,
      null
    ),
    id: index(
      local!data,
      &amp;#39;recordType!{813c8d12-c70d-4373-b9d3-bbb60dbb1d56}Employee Detail.fields.{a79c1c0e-7077-44ca-85f6-de6f4b0d969c}id&amp;#39;,
      null
    ),
    
  ),
  /*Replace the record and reference type*/
  local!uniqueLastName: union(
    local!lastName.lastName,
    local!lastName.lastName
  ),
  local!latestIds: a!flatten(
    a!forEach(
      items: local!uniqueLastName,
      expression: {
        max(
          index(
            local!lastName.id,
            wherecontains(
              tostring(fv!item),
              touniformstring(local!lastName.lastName)
            ),
            null
          )
        )
      }
    )
  ),
  a!forEach(
    items: local!latestIds,
    expression: index(
      local!data,
      wherecontains(
        tointeger(fv!item),
        tointeger(
          index(
            local!data,
            &amp;#39;recordType!{813c8d12-c70d-4373-b9d3-bbb60dbb1d56}Employee Detail.fields.{a79c1c0e-7077-44ca-85f6-de6f4b0d969c}id&amp;#39;,
            null
          )
        )
      ),
      null
    )
  )
)
/*Tried out in my apprach a better and efficient way might also be available. Till then this might do the job*/&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Please update the data and the indexes to work according to your data.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting data group by field and the latest one</title><link>https://community.appian.com/thread/128666?ContentTypeID=1</link><pubDate>Thu, 01 Feb 2024 11:54:23 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:65a4b86f-f1ed-4c6a-93a0-b914aebe2dc3</guid><dc:creator>Mathieu Drouin</dc:creator><description>&lt;p&gt;Did you take a look at the union function?&lt;/p&gt;
&lt;p&gt;&lt;a id="" href="https://docs.appian.com/suite/help/23.4/fnc_set_union.html"&gt;https://docs.appian.com/suite/help/23.4/fnc_set_union.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;union(
    local!trainingData.trainingName,
    local!trainingData.trainingName,
  )&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>