Need Script for throwing an error for duplicate entry

malaisamy1
Kilo Contributor

Hi Guys,

I have a requirement as below,

i have a field called 'invoice_no' in a form.

when we open a record which is already created and when we click the button submit it has to give an error 'Duplicate Entry' if the field value(invoice_no) for the record is alreadty there in the another record.

for example:

if in one record the value for invoice_no is : JM1234

and in second record the value for invoice_no is : JM1234   same

then when we click the button(inside any of the record) it has to say that already one record exist for this field invoice_no;

Can someone help me on this scenario?

Thanks in advance

Malaisamy

1 ACCEPTED SOLUTION

Use this code in your ui action:



var t=current.getValue('field_name');


var gr=new GlideRecord('table_name');


gr.addQuery('field_name!=""');


gr.query();


while(gr.next())


  {


  if(gr.field_name==t)


  {


  gs.addInfoMessage('There is a record with same invoice number');


  //current.setAbortAction(true);   //use this if you don't want to update the record or use current.update()


  break;


  }


  else


  current.update();


}



let me know if this helps.



Thanks


Priyanka


View solution in original post

8 REPLIES 8

malaisamy1
Kilo Contributor

Hi Priyanka,



It works perfectly... Thanks for the support


Can you please mark the answer correct and close this thread so that others find it useful.



Thanks


Priyanka.


malaisamy1
Kilo Contributor

Hi Priyanka,



I am not getting the 'correct answer button'. SO that i have marked this as useful.



Let me know if you want me to do anything


Need Script for throwing an error for duplicate entry   open link and mark the correct answer.



Thanks,


Priyanka