Repeating Table Validation for duplicate records - InfoPath Dev
in

InfoPath Dev

Having trouble finding a blog or post that answers your question? Check out our Custom Search Page

Repeating Table Validation for duplicate records

Last post 01-18-2013 04:23 AM by rvacchi. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 02-06-2009 01:18 PM

    Repeating Table Validation for duplicate records

    Hi,

    In repeating table, when user inserts new item, I want to check for duplicate record in repeating table. If user enters any existing record (e.g: "MaterialID") then display message box otherwise allow user to enter new Material ID. Any thoughts ?

     Thanks is advance.

  • 02-06-2009 10:10 PM In reply to

    Re: Repeating Table Validation for duplicate records

    Hi,

    You can avoid the duplicate values by putting the following expressions as data validation.

    count(/my:myFields/my:group1/my:group2[my:field2 != ""]) > 1 and (. = ../preceding-sibling::my:group2/my:field2 or . = ../following-sibling::my:group2/my:field2)

    and add the message to display the dialogue box.

    Here /my:myFields/my:group1/my:group2 -> repeating group xpath

    My:field2 -> field in repeating table

    Swathip
    www.ggktech.com
  • 02-09-2009 09:59 AM In reply to

    Re: Repeating Table Validation for duplicate records

    swathip,

    Thanks for your reply. Your solution worked like a charm.

    This expression won't check for uppercase or lowercase. (Example: If i enter "infopath" and have "INFOPATH" already in repeating table then it wont display message. It considers as different values).

    I modified default value setting for textbox(my:field2) to "translate(., "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ")". This expression converts input value to Uppercase. 

    Again, Thanks for your help. Have a nice day...

  • 03-23-2009 02:45 PM In reply to

    Re: Repeating Table Validation for duplicate records

    I want to follow up on this solution with the following scenario.

    I have a repeating table with a dropdown controls. The dropdown has its data validation set up with the suggested expression.

    Validation works just fine when a row is added to the table and a duplicate value is selected in the dropdown. The problem with it though that when I change the value of a sibling item with the same value the validation message does not clear off from the added dropdown even though it is not a duplicate anymore.

    It looks like validation event does not fire. Is this happening because the change is made on a different row?

    I would appreciate if somebody can suggest how to handle this. Thanks.

     

  • 02-21-2010 02:42 PM In reply to

    • Aditya
    • Top 150 Contributor
      Female
    • Joined on 01-26-2010
    • Sydney
    • Posts 59

    Re: Repeating Table Validation for duplicate records

    HI,

    I am also looking for something like this solution.I had a text box where user can enter data.That textbox is in repeating table.I want to make sure user have not typed same data in different tables.

    Xpath for the field to validate:/my:Main/my:Titles/my:Details/my:IMNDetails/my:CRFH_IMN1

    Xpath for the group:/my:Main/my:Titles/my:Details/my:IMNDetails

    Now can u please help me where can i set the data validation  said in the below lines.ie;do i need to set that for the field's(textbox) data validation ?

    ---------------------------------------------------------------------------------------------------------------------

    You can avoid the duplicate values by putting the following expressions as data validation.

    count(/my:myFields/my:group1/my:group2[my:field2 != ""]) > 1 and (. = ../preceding-sibling::my:group2/my:field2 or . = ../following-sibling::my:group2/my:field2)

    and add the message to display the dialogue box.

    Here /my:myFields/my:group1/my:group2 -> repeating group xpath

    My:field2 -> field in repeating table

    ----------------------------------------------------------------------------------------------------------------------

    Aditya,
    .Net programmer.
  • 04-22-2010 08:47 AM In reply to

    Re: Repeating Table Validation for duplicate records

     After studying this for some time I cannot get this to work.

    The first part

    count(/my:myFields/my:group1/my:group2[my:field2 != ""]) > 1

    is working ok but I cannot find any working examples of preceding-sibling or following-sibling

    (. = ../preceding-sibling::my:group2/my:field2 or . = ../following-sibling::my:group2/my:field2)

    I had a look at this blog article but it's a bit too vague for me.

  • 07-20-2010 05:16 AM In reply to

    Re: Repeating Table Validation for duplicate records

    Hi all, I have a similar situation. When I used the following code, it worked perfect, it successfully throws an error when duplicate values are entered.

    count(/my:myFields/my:group1/my:group2[my:field2 != ""]) > 

    (. = ../preceding-sibling::my:group2/my:field2 or . = ../following-sibling::my:group2/my:field2)

     

    However, in my situation, I have another field in the repeating table, lets say field1. If the text in field1 is the same in any of two or more rows in the repeating table, then field 2 value cannot be the same for the same rows. e.g, in the below example, FIELD2 CANNOT have 55 in both the rows, since the value of FIELD1 is the same (Henry), in both of these rows, as in this example.

    FIELD1    FIELD2

    Henry        55

    Henry        55

     

    However if the value in FIELD1 is different, then FIELD2 should allow duplicate values like shown below:

     

    FIELD1    FIELD2

    Henry        55

    George        55

     

    How should my expression be formed. Any help is greatly appreciated :)

  • 07-20-2010 06:53 AM In reply to

    Re: Repeating Table Validation for duplicate records

    I used code behind in the end.

    Private Function searchForDuplicate(ByVal xpNav As XPathNavigator, ByVal xpIterator As XPathNodeIterator) As Boolean

    Dim findItem As String
    Dim nodeset As New List(Of String)

    While
    xpIterator.MoveNext
    Dim programme As String = ""
    xpNav = xpIterator.Current
    nodeset.Add(xpNav.Value.Trim)
    End While

    Dim countForDuplicates As Integer

    For Each item As String In nodeset
    If item <> "" Then
    findItem = item
    For Each item2 As String In nodeset
    If findItem = item2 Then
    countForDuplicates += 1
    End If
    Next

    End If

    If countForDuplicates > 1 Then

    ' Duplicate found!

    Return True

    Exit Function

    End If

    countForDuplicates = 0

    Next

    Return False

    End Function

  • 04-26-2011 02:40 AM In reply to

    Re: Repeating Table Validation for duplicate records

    Hello, I think after so long time somebody facing this issue ...! anways. guys I applied all these steps equivalent to my infopath and datasource architecture. but unfortunatly i could not succeed. So i tried this last option to find duplicate in code behind, in which i got success , even i am showing the pop up box with message "Can not insert duplicate records". but client requirement in i must be highlighht which row / record in the repeating table get duplicating. same like data validation (red dashed border). At my end , preceding sibling and following sibling are not working. so i chose code behind to find. what should be the reason these are not functioning? I i want to make dashed border erepeating table row from code behind , what i have to do . pleae guide. I am new in infopath actually. your guidance may save me from give up . thanks Jwells!

  • 04-26-2011 03:51 AM In reply to

    Re: Repeating Table Validation for duplicate records

    You can do this with conditional formatting.

    Instead of testing for duplicates True or False, return the duplicate value. (Only problem here is what if more duplicate values? e.g. {1,2,2,4,4,5})

    Store the duplicate value in a node and change formatting of the repeating item if it is = to duplicate value.

  • 01-18-2013 04:23 AM In reply to

    Re: Repeating Table Validation for duplicate records

    Hi Aditya

    I hope you are well. Managed to put the xpath query as a expression as data validation

    I did not understand this part

    and add the message to display the dialogue box.

    Here /my:myFields/my:group1/my:group2 -> repeating group xpath

    My:field2 -> field in repeating table

    I replicated the above with my field 

     

Page 1 of 1 (11 items)
Copyright © 2003-2014 Qdabra Software. All rights reserved.
View our Terms of Use.