How to call script include in background script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2019 09:15 AM
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();
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2019 09:17 AM
Backgound script
new GetDemandChangesLastQuarter().DemandFunction();
Looks like issue in script includes newvalue=-4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2019 09:31 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2019 09:47 AM
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);
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2019 09:51 AM
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