- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2016 09:34 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2016 10:50 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2016 09:49 PM
Hi Malaisamy,
I think there is no need of script. Just once follow this steps to achieve your requirement and let me know.
1)Go to the table where invoice_no field is present.
2)Make unique as true for that field.
3)If there are records with same invoice_no it doesn't allow you to update, so just remove the duplicate records, make that field unique again and update it.
4)Now when you try to insert/update the records with same invoice_no, it will show duplicate entry.
Hope this helps!
Thanks,
Priyanka.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2016 10:09 PM
Hi Priya,
I am already aware of that unique option.
My requirement is
it has to allow user to create record with the duplicate value.
but when other user opens any of the record which has the duplicate value for the field 'invoice_no'
and when he clicks some button(we have a button called 'Validate') it has to give me an error by saying already there is a record already for this invoice_no.
the validation has to happen once the user clicks the button.
Can you help on this?
Malaisamy J
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2016 10:50 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2016 11:45 PM
Hi Malaisamy,
is it working?