- 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-21-2016 02:40 AM
Hi,
Your User table is not available for scoped application.
you need to contact ServiceNow.
Or Create an incident on Hi.
they will help you :0
- 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 02:45 AM
Hi Tolga,
Its really amazing..super..it works perfectly like i wanted.
I Have one more requirement. Could you please help me on this,
i have one date field called invoice_date where i have one more field called day_s
where day_s has dropdown values like 10,15, 30 so on.
my result field = invoice_date + day_s
that is it has to add the days whatever there in the day_s field. and stored in my result field.
result field is a date field.
Is it possible? Do you have any idea?
Thanks in Advance,
Malaisamy Ji
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2016 03:14 AM
Hi Malaisamy
I'm glad, my solution helped. May I please ask you to mark my answer as "correct", if it resolved your issue?
As you already opened a new thread on your additional question, I'd propose to discuss it there and closed this thread (as it is a different topic), if okay for you.
Best Regards
Tolga