How to call script include in background script

dilini
Giga Expert

I am trying to call following script include in my background script as follows but, not successful?
My script include: 


var GetDemandChangesLastQuarter = Class.create();
GetDemandChangesLastQuarter.prototype = {
initialize: function() {},
DemandFunction :function(){
var demandList = [];
var queryString = "tablename=dmn_demand^sys_created_onONLast fiscal quarter@javascript:gs.beginningOfLastSchedulePeriod('b198ae11d7222100738dc0da9e6103d7','Last fiscal quarter')@javascript:gs.endOfLastSchedulePeriod('b198ae11d7222100738dc0da9e6103d7','Last fiscal quarter')^fieldname=state^newvalue=-4";
var gr = new GlideRecord('sys_audit');
gr.addEncodedQuery(queryString);
gr.query();
while (gr.next()) {
gs.addInfoMessage(gr.number);
}
},
type:'GetDemandChangesLastQuarter'};

 

Call in script-background:

var DemandList =new GetDemandChangesLastQuarter();
DemandList.DemandFunction();

4 REPLIES 4

Mike Patel
Tera Sage

Backgound script

new GetDemandChangesLastQuarter().DemandFunction();

 

Looks like issue in script includes newvalue=-4

Kaushik Muley1
Giga Contributor

Your method of calling script include in background script looks ok. Try using simpler encoded query to your glide record to check if it is getting stuck somewhere in script include itself.

vkachineni
Kilo Sage
Kilo Sage

1. What is the scope of the SI?

2. Is it available to other scopes

3. Are you in a different scope while running the background script.

4. use a simple encoded query to start with.

5. Return a string of numbers in your SI

var arr = [];

while (gr.next()) {
arr.push(gr.number);
}

return arr.toString();

 

6. Back ground script

var DemandList =new GetDemandChangesLastQuarter();
var str = DemandList.DemandFunction();

gs.info('str = ' + str);

 

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

Tim Provin
Mega Guru

What are you seeing when you run the bockground script?  Your script include is just trying to display an info message, and it won't display the same way in a background script as if it were running in a business rule.  You will only get a message stating that it ran a background message and what the message is.  See below

find_real_file.png