- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2016 02:37 AM
Hi Guys,
Here i have one problem,
i want a ui action script for finding duplicate records.
My scenario is , if the field invoice_no has same value for two different record over the list,
when i click my ui action button it has to give me an error y saying already one record is there for this field invoice_no.
Is it possible. Can someone help me?
please find my below code
- getDuplicates();
- function getDuplicates() {
- var dupRecords = [];
- var gaDupCheck1 = new GlideAggregate('sys_user');
- gaDupCheck1.addQuery('active','true');
- gaDupCheck1.addAggregate('COUNT', 'user_name');
- gaDupCheck1.groupBy('user_name');
- gaDupCheck1.addHaving('COUNT', '>', 1);
- gaDupCheck1.query();
- while (gaDupCheck1.next()) {
- dupRecords.push(gaDupCheck1.user_name.toString());
- }
- gs.print(dupRecords);
- }
its giving me an error 'addHaving is not allowed in scoped applications'
Is there any alternate solution for this scenario?
Thanks in Advance
Malai
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2016 01:11 AM
What about using a business rule instead with this code on insert/update?
(function executeRule(current, previous /*null when async*/) {
// Add your code here
if (current.invoice_no &&
(current.operation() == "insert" ||
(current.operation() == "update" && current.invoice_no.changes()))) {
var gr = new GlideRecord("table_where_invoice_no_is");
gr.addQuery("invoice_no", current.invoice_no);
gr.query();
if (gr.getRowCount() > 0) {
current.setAbortAction(true);
gs.addErrorMessage(gs.getMessage("Not allowed the duplicate invoice_no=" + current.invoice_no));
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2016 03:30 AM
Hi Tolga,
I have already marked as correct answer and helpful.
Please find my another issue here. I have raised one more discussion.
Please help me on this.
Malaisamy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2016 03:30 AM