Script Include Not Working on getrowcount

sumityadav8
Tera Contributor
var countofrec = Class.create();
countofrec.prototype = {
    initialize: function() {
    },

    reco: function (xyz,desc) {
        var gr = new GlideRecord("xyz");
        gs.addInfoMessage("Inside Script Include");
        gr.addQuery('short_description','CONTAINS',desc);
        gr.query();
        gs.addInfoMessage(gr.getRowCount());
        return  gr.getRowCount();
    },

    type: 'countofrec'
};
 
I am calling this script Include via BR, but it is not Working,Please help
3 ACCEPTED SOLUTIONS

Bhuvan
Mega Patron

@sumityadav8 

 

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,

Bhuvan_0-1757441198467.png

Bhuvan_1-1757441214027.png

Bhuvan_0-1757441879555.png

If this helped to answer your query, please mark it helpful & accept the solution. 

 

Thanks,

Bhuvan

View solution in original post

Shruti D
Kilo Sage

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

 

View solution in original post

Chaitanya ILCR
Mega Patron

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

View solution in original post

6 REPLIES 6

Chaitanya ILCR
Mega Patron

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

Ankur Bawiskar
Tera Patron
Tera Patron

@sumityadav8 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader