cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Duplicate field value in Trigger

Highlighted
Granite

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 4
Highlighted

Re: Duplicate field value in Trigger

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

Highlighted

Re: Duplicate field value in Trigger

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.

Highlighted

Re: Duplicate field value in Trigger

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

Highlighted

Re: Duplicate field value in Trigger

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.

Announcements