Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Preventing duplicate records

(0) ShareShare
ReportReport
Posted on by

A table has two fields. one is "empcode" and other one is enum "Gender" which has 2 values say "Male" & "Female".

If there is one record with empcode "0003" of gender "Male" in the system. When user tries to create one more record in system with same empcode  "0003" and same Gender "Male" then, system should not accept it. 

How to write the code so that it throws error message "Record already exists".

But if empcode is same and Gender is not same then it should accept.

 

  • Verified answer
    nmaenpaa Profile Picture
    101,156 Moderator on at
    RE: Preventing duplicate records

    Hi Aniket,

    nice to hear that it's now working. If your problem is solve, could you please mark the helpful answer(s) as verified, so that this question will be marked as Answered. Thanks!

  • Community Member Profile Picture
    on at
    RE: Preventing duplicate records

    Okay . Actually I was facing DB sync Error. And I'm new to this technology. So, couldn't figure it out . Anyway error resolved now.

    Thank you :-)

  • Verified answer
    nmaenpaa Profile Picture
    101,156 Moderator on at
    RE: Preventing duplicate records

    Ok, so you still haven't synchronized the database. Please do it (click "Continue") in the Synchronize database dialog.

    Before that, the changes are not synchronized in the database, as I told you before.

    Also you still didn't share enough information about your index. We don't see what fields are in it. 

    Please try to pay attention to what's written to you, if you ask for help. This way you maximize the likelihood of solving your problem.

  • Community Member Profile Picture
    on at
    RE: Preventing duplicate records

    Okay .

    Please find below Index Properties :

    pastedimage1616063309052v1.png

    So, after this step I'm getting below error when i try to sync the data : 

    pastedimage1616063417231v2.png

    The message was "These messages can describe data loss, partitioning loss, or other issues that must be reviewed before continuing."

  • Verified answer
    Martin Dráb Profile Picture
    231,933 Most Valuable Professional on at
    RE: Preventing duplicate records

    Yes, I understand your requirement all the time. I just pointed out that your picture was wrong. It said that duplicate records should be accepted; which is not true, according to your textual explanation.

    If you don't give us any information about your index, let's stop this discussion, because the lack of information from you prevent us from helping you.

  • Community Member Profile Picture
    on at
    RE: Preventing duplicate records

    Yes there are  two XYZ types and no ABC because that is user input it can be anything.

    Please find below screenshot for reference :

    UserInput.png

    So, the requirement is ,  for second statement  .. it should not accept and  it must throw error .

    but for third statement, it should accept.

    I hope it is more clear now.

  • Verified answer
    Martin Dráb Profile Picture
    231,933 Most Valuable Professional on at
    RE: Preventing duplicate records

    Could you please look at your picture again:

    SameCode_2600_DifferentType.PNG

    Do really see there "one record with code 0003 of type ABC" and "one more record in system with code “0003” code of type XYZ"?. I do not. I see two XYZ types and no ABC.

    Could you please finally sbhow us a screenshot of properties your index?

  • Community Member Profile Picture
    on at
    RE: Preventing duplicate records

    Hi,

    Requirement is same. There is no change. I'm trying to explain with multiple examples. The picture is sample user inputs.

    So, in first picture , that kind of input is  not acceptable.

    In second picture, that kind of input is acceptable.

    So, I need to write the code which accepts user inputs and check the two conditions.

    Please find below conditions :

    1- If there is one record with code “0003” of type ABC in system. When user tries to create one more record in system with code “0003” code of type ABC then should not accept. Error message will be “Cannot create a record in Custom list ABC and XYZ code. Code: 0003. The record already exists. "

    2 - If there is one record with code “0003” of type ABC in system. When user tries to create one more record in system with code “0003” code of type XYZ then should accept.

  • Verified answer
    Martin Dráb Profile Picture
    231,933 Most Valuable Professional on at
    RE: Preventing duplicate records

    Your picture doesn't match description. You're saying that it should accept 123/ABC and 123/XYZ, but you last picture shows XYZ two times. I'll assume that the picture is wrong and you just still haven't noticed it.

    What are you referring to when saying "Can you explain bit clearly what changes exactly I have to do?".

    Note that you don't need any X++, just the index. You can easily see the standard behavior - for example, try to insert two customer groups with the same name.

    By the way, I still don't see any information from you about the index. We can't help you if you don't give us necessary information.

  • Community Member Profile Picture
    on at
    RE: Preventing duplicate records

    Hello,

    Yes , requirement is same . I'm trying to explain you with examples.  

    Please find below conditions :

    1- If there is one record with code “0003” of type ABC in system. When user tries to create one more record in system with code “0003” code of type ABC then should not accept. Error message will be “Cannot create a record in Custom list ABC and XYZ code. Code: 0003. The record already exists. "

    2 - If there is one record with code “0003” of type ABC in system. When user tries to create one more record in system with code “0003” code of type XYZ then should accept.

    I hope you understand it clearly !

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,274 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,933 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans