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

Jim Coyne
Kilo Patron
  1. What does "but it is not Working" mean?  What have you tried?  What have been the results?
  2. 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)
  3. What about the row count message?
  4. 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.

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

 

@sumityadav8 

 

Did you get a chance to review this as I believe the information provided should resolve your issue.

 

As per community guidelines, you can accept more than one answer as accepted solution. If my response helped to answer your query, please mark it helpful & accept the solution.

 

Thanks,

Bhuvan

 

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