- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 03:33 PM
Hi,
I'm having issues in a Business Rule I created to update a field called "u_pds_r_d_data_target". I'm using a Script Include, this one works fine on a Catalog Client Script, I already tested it, but I need it in a customized table.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var ajax = new GlideAjax('beforeOneMonth'); //Call the Script include
ajax.addParam('sysparm_name', 'monthBefore'); //Call the function
ajax.addParam('sysparm_value', newValue); //Call the selected value of 'Date of Separation'
ajax.getXML(doSomething); //Declare callback function
function doSomething(response) {
var answer = response.responseXML.documentElement.getAttribute("answer"); //Set the script include return value in 'answer' variable
current.u_pds_r_d_data_target = answer; //Provide the variable name of 'Date of access removal' where the date will be set
gs.addInfoMessage('Refreshed');
current.update();
}
})(current, previous);
This is what I have in the When to run which I'm sure it is fine I as changed the script for something simple to update another field.
And this is the Script Include:
//I created this Script Include for UDI Team to calculate a month before the launch date
var beforeOneMonth = Class.create();
beforeOneMonth.prototype = Object.extendsObject(AbstractAjaxProcessor, {
monthBefore: function() {
var date = this.getParameter('sysparm_value');
date = date.toString();
var gdt = new GlideDateTime(date).getDate();
gdt.addMonths(-1);
var gdtStr = gdt.toString();
return gdtStr;
}
});
Can anyone help me to figure out this?
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2022 11:03 AM
I figured this out. I passed the parameter within the function in the Script Include
I commented out the line I used to pass the parameter for Client Script and added the parameter within the function.
var BeforeOneMonth = Class.create();
BeforeOneMonth.prototype = {
initialize: function() {},
monthBefore: function(launchDate) {
// var date = this.getParameter('sysparm_value');
launchDate = launchDate.toString();
var gdt = new GlideDateTime(launchDate).getDate();
gdt.addMonths(-1);
var gdtStr = gdt.toString();
return gdtStr;
},
type: 'BeforeOneMonth'
};

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 04:13 PM
beforeOneMonth.prototype = Object.extendsObject(AbstractAjaxProcessor, {
initialize :function(){},
myFunction :function(){//Put function code here},
type :'beforeOneMonth '};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 04:16 PM
Hi, you indicate that you are calling a script-include from a business rule,
yet your post shows a GlideAjax script-include and this type of script-include would normally be 'called' from a client script (or as you stated in your post a catalog client script).
The method used for passing in parameters to GlideAjax and a normal server-side script-include is different.
GlideAjax uses this.getParameter('sysparm_parameter1');
and a normal script-include function uses
scriptIncludeName().functionName(parameter1, parameter2, parameter3); // etc
It is possible to alter a GlideAjax script-include so that it can be called from client or server side script,
but this is not common and the result may cause future confusion with developers who follow.
Can you clarify your requirements\business drivers?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2022 09:45 AM
Thanks for your answer. It's clear now that GlideAjax is for Client Script.
My requirement is to create a business rule that when the Launch Date field changes to any date, the Target field automatically changes to one month before the Launch Date.
I did in a Catalog Item (form) and it was working fine. Now, the team wants it in a customized table.
I know I need a Script Include but not sure how to do it as well as script in the business rule.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2022 05:52 PM
Hi Diorella,
Tony's points are correct. Can't just copy script from onChange() client script into business rule. For one, there's no "newValue" in business rule function argument.
Business rule script should be something like below.
(function executeRule(current, previous /*null when async*/ ) {
var bom = new BeforeOneMonth(); //Call the Script include
current.u_pds_r_d_data_target = bom.monthBefore(current.date_of_separation); // replace with actual name of variable
gs.addInfoMessage('Refreshed');
current.update();
}
)(current, previous);
and matching Script Include is like below
var BeforeOneMonth = Class.create();
BeforeOneMonth.prototype = {
initialize: function() {},
monthBefore: function() {
var date = this.getParameter('sysparm_value');
date = date.toString();
var gdt = new GlideDateTime(date).getDate();
gdt.addMonths(-1);
var gdtStr = gdt.toString();
return gdtStr;
},
type: 'BeforeOneMonth'
};