- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Since you are passing the values from BR, remove double quotes from table name. Correct the syntax and try, it should work
Below is sample,
If this helped to answer your query, please mark it helpful & accept the solution.
Thanks,
Bhuvan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hello @sumityadav8
Try with below updated script include:
var countofrec = Class.create();
countofrec.prototype = {
initialize: function() {
},
reco: function(tableName, desc) {
var gr = new GlideRecord(tableName); // use table name
gs.addInfoMessage("Inside Script Include");
gr.addQuery('short_description', 'CONTAINS', desc);
gr.query();
var count = gr.getRowCount();
gs.addInfoMessage("Row count: " + count);
return count;
},
type: 'countofrec'
};
Business Rule for example:
(function executeRule(current, previous /*null when async*/) {
var recCount = new countofrec().reco('incident', current.short_description); //replace your table name
gs.addInfoMessage("Records found: " + recCount);
})(current, previous);
Please Mark Correct ✔️ if this solves your query and also mark Helpful 👍 if you find my response worthy based on the impact.
Regards,
Shruti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @sumityadav8 ,
update your script include as this
var countofrec = Class.create();
countofrec.prototype = {
initialize: function() {},
reco: function(xyz, desc) {
var gr = new GlideRecord(xyz);
gs.info("Inside Script Include");
gr.addQuery('short_description', 'CONTAINS', desc);
gr.query();
gs.info(' row count = ' + gr.getRowCount());
return gr.getRowCount();
},
type: 'countofrec'
};
you can call the script include like this (example table I have chosen is incident and example short_description is test)
you can replace incident with your table name and test with your short_description
var noOfRows = new countofrec().reco('incident','test')
you can store and use the value in a variable like noOfRows
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @sumityadav8 ,
update your script include as this
var countofrec = Class.create();
countofrec.prototype = {
initialize: function() {},
reco: function(xyz, desc) {
var gr = new GlideRecord(xyz);
gs.info("Inside Script Include");
gr.addQuery('short_description', 'CONTAINS', desc);
gr.query();
gs.info(' row count = ' + gr.getRowCount());
return gr.getRowCount();
},
type: 'countofrec'
};
you can call the script include like this (example table I have chosen is incident and example short_description is test)
you can replace incident with your table name and test with your short_description
var noOfRows = new countofrec().reco('incident','test')
you can store and use the value in a variable like noOfRows
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
what debugging did you do then?
1 mistake you have
var gr = new GlideRecord(xyz);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader