Skip to main content
1-Visitor
January 22, 2015
Question

Duplicate field value in Trigger

  • January 22, 2015
  • 2 replies
  • 2326 views

I have an Integer field created (Integer_fld) and would like to create a trigger that checks for duplicate values for previous created items items.

I tried a script from a previous discussion, but could not make it work. I thought I would start a new discussion for this.

EXAMPLE:

List of Items

ID State Integer_fld Txt_fld

100 Initiate 10023 Some text here...

101 Initiate 10024 Some more text here...

I create a new Item ID 102 and for the Integer_fld I enter 10023. When I try to save it I would like to see an error message stating it is a duplicate. ID 100 has the same value in the Integer_fld.

Thank you,

Dan

    2 replies

    16-Pearl
    January 23, 2015

    Hi Daniel,

    there is another post that already covered this problem

    Re: Duplicate Checking in Trigger

    Can you specify whether your current problem is different?

    HTH Matthias

    DanR.1-VisitorAuthor
    1-Visitor
    January 23, 2015

    Matthias,

    I started a new discussion because the script from that discussion did not work for me. I tried the one attached to the discussion. I'm simply trying to compare an Integer field of a new issue compared to all existing issues. The comparison would check for duplicate and if there was an error message would be displayed. This would obviously be a pre-event trigger.

    DanR.1-VisitorAuthor
    1-Visitor
    February 2, 2015

    I thought this would be easy and someone might have a workable solution. I believe my use case example provides enough information.

    1-Visitor
    February 3, 2015

    I'm assuming that the problem here is that this code compares strings and you are looking to compare integers.

    this:

    queryBuf.append('(');

    queryBuf.append("field[");

    queryBuf.append(singletonField);

    queryBuf.append("]=");

    queryBuf.append(currentValue);

    queryBuf.append('"');

    queryBuf.append(')');

    Produces a query that reads: if (field[ExistingStringValue]="InputStringValue") ...

    Working with integers, I'd use something more like: if (ExistingIntValue.equals(InputIntValue)) ...

    Try rewriting the query building lines to work with integers instead of strings and it should work for you.