- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 10:19 AM
Scenario: To prevent duplicate ritms
This script is working fine, but I want to be implemented with GlideAgrigate instead of getRowCount. Can you please help me out, Thanks in advance.
var validate_duplicates = class.create();
validate_duplicates.prototype = object.extendsObject(AbstractAjaxProcessor, {
Validation: function (){
var SApp=this.getParameter('sysparm_user);
var ritms = new GlideRecord('sc_req_item');
ritms.addQuery('cat_item', 'sys_id');
ritms.addQuery('configuration_item', SApp);
ritms.addQuery('state', 'IN' , [1,2]);//ritm state=open and work in progress
ritms.query();
if(ritm.getRowCount()==0)
return true;
else
return false;
},
type:'validate_duplicates'
});
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 10:33 AM
@Umesh G Here is the script you should try
var validate_duplicates = class.create();
validate_duplicates.prototype = object.extendsObject(AbstractAjaxProcessor, {
Validation: function (){
var ritms = new GlideAggregate('sc_req_item');
ritms.addAggregate('COUNT');
ritms.addQuery('cat_item', 'sys_id');
ritms.addQuery('configuration_item', SApp);
ritms.addQuery('state', 'IN', [1, 2]); //ritm state=open and work in progress
ritms.query();
if (ritms.next()) {
if (ritms.getAggregate('COUNT') == 0) {
return true;
} else {
return false;
}
}
},
type:'validate_duplicates'
});
Please mark my answer helpful and correct if it manages to address your requirement.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 10:31 AM
Hi @Umesh G
You could use GlideAggregate, but you don't have to, to avoid getRowCount, at least for this use case.
Try this:
var validate_duplicates = class.create();
validate_duplicates.prototype = object.extendsObject(AbstractAjaxProcessor, {
Validation: function (){
var SApp=this.getParameter('sysparm_user);
var ritms = new GlideRecord('sc_req_item');
ritms.addQuery('cat_item', 'sys_id');
ritms.addQuery('configuration_item', SApp);
ritms.addQuery('state', 'IN' , [1,2]);//ritm state=open and work in progress
ritms.setLimit(1); //No need to search for more than 1 record
ritms.query();
if(!ritm.hasNext()){
return true;
}
else{
return false;
}
},
type:'validate_duplicates'
});
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 10:33 AM
@Umesh G Here is the script you should try
var validate_duplicates = class.create();
validate_duplicates.prototype = object.extendsObject(AbstractAjaxProcessor, {
Validation: function (){
var ritms = new GlideAggregate('sc_req_item');
ritms.addAggregate('COUNT');
ritms.addQuery('cat_item', 'sys_id');
ritms.addQuery('configuration_item', SApp);
ritms.addQuery('state', 'IN', [1, 2]); //ritm state=open and work in progress
ritms.query();
if (ritms.next()) {
if (ritms.getAggregate('COUNT') == 0) {
return true;
} else {
return false;
}
}
},
type:'validate_duplicates'
});
Please mark my answer helpful and correct if it manages to address your requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 11:01 AM
Working perfectly, Thank you very much for your response.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 11:04 AM
Hi @Umesh G,
Great that it works for you, however performance wise you should use my solution.
You are now looking up all records in the table to find if there is more than 1.
When you just set a limit to the number of records (1) and check if you find a record, it will execute a lot faster.
You should use GlideAggregate if you need to know the amount of records, not to see if there are records.
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.