Skip to main content
1-Visitor
Jan 22, 2015 2:49 PM UTC
Question

Duplicate field value in Trigger

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

    4 replies

    16-Pearl
    Jan 23, 2015 7:57 AM UTC

    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

    Translate
    DanR.1-VisitorAuthor
    1-Visitor
    Jan 23, 2015 2:02 PM UTC

    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.

    Translate
    DanR.1-VisitorAuthor
    1-Visitor
    Feb 2, 2015 6:53 PM UTC

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

    Translate
    1-Visitor
    Feb 3, 2015 8:13 PM UTC

    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.

    Translate