<?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>Duplicate check in a dynamic grid layout</title><link>https://community.appian.com/discussions/f/general/11878/duplicate-check-in-a-dynamic-grid-layout</link><description>Hi, I have a text field in dynamic grid layout. How do i check for a duplicate entry and generate a error message in validation? 
 (I&amp;#39;m storing the entries from the text field in a rule input of cdt type)</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Duplicate check in a dynamic grid layout</title><link>https://community.appian.com/thread/112354?ContentTypeID=1</link><pubDate>Mon, 08 May 2023 13:22:03 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:cb9e3315-6a32-4fe2-b178-3b3a2906b149</guid><dc:creator>vaibhavm7394</dc:creator><description>&lt;p&gt;Hi Arpit&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;  a!localVariables(
    local!data:rule!D_Demo_excel_Data(data:ri!input),
    {
      
      a!gridLayout(
        label: &amp;quot;Student Data&amp;quot;,
        labelPosition: &amp;quot;ABOVE&amp;quot;,
        headerCells: {
          a!gridLayoutHeaderCell(label: &amp;quot;Roll_No&amp;quot;),
          a!gridLayoutHeaderCell(label: &amp;quot;Name&amp;quot;),
          a!gridLayoutHeaderCell(label: &amp;quot;Subject_1&amp;quot;),
          a!gridLayoutHeaderCell(label: &amp;quot;Subject_2&amp;quot;),
          a!gridLayoutHeaderCell(label: &amp;quot;Subject_3&amp;quot;),
          a!gridLayoutHeaderCell(label: &amp;quot;Subject_4&amp;quot;),
          a!gridLayoutHeaderCell(label: &amp;quot;Total_Percentage&amp;quot;),
          a!gridLayoutHeaderCell(label: &amp;quot;Grade&amp;quot;),
        },
        columnConfigs: {},
        rows: {
          a!forEach(
            items: ri!data,
            expression: a!localVariables(
              a!gridRowLayout(
                contents: {
                  a!integerField(
                    value: fv!item.Roll_No,
                    saveInto: fv!item.Roll_No,
                    readOnly: true
                  ),
                  a!textField(
                    value: fv!item.Name,
                    saveInto: {fv!item.Name,a!save(fv!item.Total_Percentage,{((fv!item.Subject_1) + (fv!item.Subject_2) + (fv!item.Subject_3) + (fv!item.Subject_4) )/4}),a!save(fv!item.Grade,rule!D_excelGrade(percentage: fv!item.Total_Percentage))},
                    required: true
                  ),
                  a!integerField(
                    value: fv!item.Subject_1,
                    saveInto: {fv!item.Subject_1,a!save(fv!item.Total_Percentage,{((fv!item.Subject_1) + (fv!item.Subject_2) + (fv!item.Subject_3) + (fv!item.Subject_4) )/4}),a!save(fv!item.Grade,rule!D_excelGrade(percentage: fv!item.Total_Percentage))},
                    required: true
                  ),
                  a!integerField(
                    value: fv!item.Subject_2,
                    saveInto: {fv!item.Subject_2,a!save(fv!item.Total_Percentage,{((fv!item.Subject_1) + (fv!item.Subject_2) + (fv!item.Subject_3) + (fv!item.Subject_4) )/4}),a!save(fv!item.Grade,rule!D_excelGrade(percentage: fv!item.Total_Percentage))},
                    required: true
                  ),
                  a!integerField(
                    value: fv!item.Subject_3,
                    saveInto: {fv!item.Subject_3,a!save(fv!item.Total_Percentage,{((fv!item.Subject_1) + (fv!item.Subject_2) + (fv!item.Subject_3) + (fv!item.Subject_4) )/4}),a!save(fv!item.Grade,rule!D_excelGrade(percentage: fv!item.Total_Percentage))},
                    required: true
                  ),
                  a!integerField(
                    value: fv!item.Subject_4,
                    saveInto: {fv!item.Subject_4,a!save(fv!item.Total_Percentage,{((fv!item.Subject_1) + (fv!item.Subject_2) + (fv!item.Subject_3) + (fv!item.Subject_4) )/4}),a!save(fv!item.Grade,rule!D_excelGrade(percentage: fv!item.Total_Percentage))},
                    required: true
                  ),
                  a!integerField(
                    value:
                    {((fv!item.Subject_1) + (fv!item.Subject_2) + (fv!item.Subject_3) + (fv!item.Subject_4) )/4},
                    /*saveInto:fv!item.Total_Percentage,*/
                   readOnly: true(),
                    required: true
                  ),
                  a!textField(
                    value: rule!D_excelGrade(percentage:fv!item.Total_Percentage),
                    /*saveInto:fv!item.Grade,*/
                    readOnly: true(),
                    required: true
                  ),
                }
              )
            )
          )
        },
        selectionSaveInto: {},
        validations: {},
        shadeAlternateRows: true
      ),
      a!buttonArrayLayout(
        buttons: {
          a!buttonWidget(
            label: &amp;quot;save&amp;quot;,

            
            submit: true,
            style: &amp;quot;NORMAL&amp;quot;
          )
        },
        align: &amp;quot;START&amp;quot;
      )
      
    }
   
  )
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I am Getting the data from a excel file and writing it to the DB. but i want to check for duplicate, like if users enters the same record they must not be written in to the DB.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Duplicate check in a dynamic grid layout</title><link>https://community.appian.com/thread/106825?ContentTypeID=1</link><pubDate>Tue, 17 Jan 2023 18:57:59 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:ad36b155-1fb8-4ae1-9bec-aa351f1a7e8d</guid><dc:creator>Mike Schmitt</dc:creator><description>[quote userid="169948" url="~/discussions/f/general/11878/duplicate-check-in-a-dynamic-grid-layout/106824#106824"]Can you please share the code for this[/quote]
&lt;p&gt;FYI this is a super-old thread - nearly 5 years now - if you&amp;#39;re having a specific issue, it might be appropriate to start your own new post now if there are no other/more recent threads that seem to deal with your issue.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Duplicate check in a dynamic grid layout</title><link>https://community.appian.com/thread/106824?ContentTypeID=1</link><pubDate>Tue, 17 Jan 2023 18:49:39 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:7ebf4f95-5285-4ac1-b713-6ff87abb5e2d</guid><dc:creator>aayushib0002</dc:creator><description>&lt;p&gt;Can you please share the code for this&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Duplicate check in a dynamic grid layout</title><link>https://community.appian.com/thread/52679?ContentTypeID=1</link><pubDate>Thu, 15 Feb 2018 14:30:04 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:64bfba42-c118-4735-8d99-0701a9ded556</guid><dc:creator>mohitshah</dc:creator><description>Hi Arpit,&lt;br /&gt;
&lt;br /&gt;
That was a really short version of that and worked completely fine. There&amp;#39;s just a slight change for multiple cdt though. &lt;br /&gt;
&lt;br /&gt;
For multiple cdt instead of replacing fv!index we can replace the index function all together with the column name. &lt;br /&gt;
Here&amp;#39;s what it it looks like for me for multiple cdt,&lt;br /&gt;
&lt;br /&gt;
if(count(wherecontains(fv!item.(columnName), ri!array.(columnName))) &amp;gt; 1&lt;br /&gt;
,&amp;quot;Duplicate&amp;quot;, &lt;br /&gt;
{}&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
Please ignore the brackets with column name.&lt;br /&gt;
&lt;br /&gt;
Regards,&lt;br /&gt;
Mohit Shah&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Duplicate check in a dynamic grid layout</title><link>https://community.appian.com/thread/52678?ContentTypeID=1</link><pubDate>Thu, 15 Feb 2018 14:20:32 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:7b5ac38d-87c1-4c01-9566-4da5dda15449</guid><dc:creator>mohitshah</dc:creator><description>Thanks Abhay . That was helpful but i got  a much optimized version of it.&lt;br /&gt;
&lt;br /&gt;
Regards,&lt;br /&gt;
Mohit Shah&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Duplicate check in a dynamic grid layout</title><link>https://community.appian.com/thread/52594?ContentTypeID=1</link><pubDate>Tue, 13 Feb 2018 12:25:04 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:7366e090-19bf-46ef-b2a5-080ad71a42d6</guid><dc:creator>Arpit Bhargava</dc:creator><description>Hi Mohit&lt;br /&gt;
&lt;br /&gt;
You can try this below code to check the duplicate in the dynamic grid layout&lt;br /&gt;
&lt;br /&gt;
forEach(&lt;br /&gt;
    items:ri!array,&lt;br /&gt;
    expression:&lt;br /&gt;
       textField(&lt;br /&gt;
          validations:{&lt;br /&gt;
              if( &lt;br /&gt;
			  count(wherecontains(ri!array,index(fv!item,fv!index,{} ))) &amp;gt;1,&lt;br /&gt;
			  &amp;quot;Duplicate&amp;quot;,{} &lt;br /&gt;
			  )  &lt;br /&gt;
					 }&lt;br /&gt;
                )&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
In place of fv!index you can use the column name if the ri!array is of multiple CDT type&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Duplicate check in a dynamic grid layout</title><link>https://community.appian.com/thread/52589?ContentTypeID=1</link><pubDate>Tue, 13 Feb 2018 09:51:18 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:aaa32cdc-c083-49d8-838f-1829c1b652e6</guid><dc:creator>Abhay Giri</dc:creator><description>Hi Mohit,&lt;br /&gt;
&lt;br /&gt;
for this error , what you can do instead of saving , you just replace the value based on Index for the existing record then i think your concern will be resolved , and still you receive error please let me know , i will share the code as well with you.&lt;br /&gt;
&lt;br /&gt;
Regards&lt;br /&gt;
Abhay Giri&lt;br /&gt;
Mark this reply as answered or vote if this helps you.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Duplicate check in a dynamic grid layout</title><link>https://community.appian.com/thread/52587?ContentTypeID=1</link><pubDate>Tue, 13 Feb 2018 09:24:10 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:4d69024f-b1cb-43f8-a15b-dbc5ba8d7dfd</guid><dc:creator>mohitshah</dc:creator><description>Hi Abhay,&lt;br /&gt;
&lt;br /&gt;
Thanks for that. It works. But there are still some issues with that. &lt;br /&gt;
&lt;br /&gt;
Like:&lt;br /&gt;
If you edit the existing duplicate textbox instead of deleting that row then it will still throw an error because when you edit the existing textbox then another entry is appended in the ri!role input instead of replacing the existing index value. &lt;br /&gt;
&lt;br /&gt;
Regards,&lt;br /&gt;
Mohit&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Duplicate check in a dynamic grid layout</title><link>https://community.appian.com/thread/52575?ContentTypeID=1</link><pubDate>Tue, 13 Feb 2018 04:08:09 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:6394ca4a-21e5-4b74-b832-83994c2e6117</guid><dc:creator>Abhay Giri</dc:creator><description>Hi Mohit,&lt;br /&gt;
&lt;br /&gt;
If i am right here, then you are adding a new row then you want to do duplicate check,right? if yes then create a rule input array type and save each value of that text field so if you added three new row then this variable will hold three different values(till now i added different values in text field). Now use the below code for validation:&lt;br /&gt;
&lt;br /&gt;
in the saveInto use the below code:&lt;br /&gt;
&lt;br /&gt;
a!save(&lt;br /&gt;
                                ri!roles,&lt;br /&gt;
                                append(&lt;br /&gt;
                                  ri!roles,&lt;br /&gt;
                                  fv!item.roleName&lt;br /&gt;
                                )&lt;br /&gt;
                              )&lt;br /&gt;
and for validation use below :&lt;br /&gt;
&lt;br /&gt;
                             if(&lt;br /&gt;
                              count(&lt;br /&gt;
                                index(&lt;br /&gt;
                                  ri!roles,(your variable name where you need to store each value)&lt;br /&gt;
                                  wherecontains(&lt;br /&gt;
                                    fv!item.roleName, (your text field value)&lt;br /&gt;
                                    ri!roles&lt;br /&gt;
                                  ),&lt;br /&gt;
                                  0&lt;br /&gt;
                                )&lt;br /&gt;
                              ) &amp;gt;= 2,&lt;br /&gt;
                              &amp;quot;Please select different Value&amp;quot;,&lt;br /&gt;
                              &amp;quot;&amp;quot;&lt;br /&gt;
                            )&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Regards&lt;br /&gt;
Abhay&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>