Script Include Not Working on getrowcount
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
54m ago
- What does "but it is not Working" mean? What have you tried? What have been the results?
- Are you getting the "Inside Script Include" message? (which should be the first line in the function, BTW, in case something throws an error before it)
- What about the row count message?
- How are you calling it from the Business Rule?
Right off the top of my head, I'd say the problem is the "var gr = new GlideRecord('xyz');" line. If you are indeed passing in the table name to the "xyz" parameter of the function, then the line should be "var gr = new GlideRecord(xyz);" (without the quotes around xyz). The way you have it, you are passing in the literal string "xyz" as the table name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
45m ago - last edited 34m 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
35m ago - last edited 25m 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
6m 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