How to pass parameters to a script include through a business rule

neil_b
Tera Guru

Hi,

 

I apologize if this has been asked before, but I couldn't find anything that was very helpful.

 

I have a business rule that runs on a custom user table (which is used to identify approval routings) where if a user is replaced, it updates any open approvals with the new user. 

 

My additional requirement is to update the watchlist with the new user as well and I need to do this through a script include so that it can be re-used for other scenarios where we update the watchlist.

 

Here is my after business rule

(function executeRule(current, previous /*null when async*/ ) {

    var previousApprover = '';
    var currentApprover = '';

 if (current.u_approver != previous.u_approver) {
        previousApprover = previous.u_approver;
        currentApprover = current.u_approver;

var gr = new GlideRecord("sysapproval_approver");
    gr.addEncodedQuery('u_approval_stateINnot requested,requested,paused^approver='previousApprover)
    gr.query
    while (gr.next()) {
			gr.approver = currentApprover;
			gr.update();
// this is where I also want to call a script include and pass the previousApprover and currentApprover as variables
// I know that for a client script, i can use this.getParameter and glideajax.addParam but since this is a business rule I wasn't sure how to accomplish this so this is my attempt
			var watchList = new global.updateWatchList(); //this is my script include name
			watchList.getCurrentWatchList();
// I'm not sure what to do next to pass the two approvers as parameters to the script include

This is my script include

var updateWatchList = Class.create();
updateWatchList.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getCurrentWatchList: function() {
// I'm not sure what to do at this point since I don't know how to pass the approvers as parameters to my script include. 
    },

    type: 'updateWatchList'
});

 

1 REPLY 1

lauri457
Giga Sage

You just define the parameters in your method definition and then you pass the data as arguments when you call that method. 

 

var watchList = new global.updateWatchList(); //this is my script include name
watchList.getCurrentWatchList(previousApprover , currentApprover); //names don't need to match
...
getCurrentWatchList: function(previousApprover , currentApprover) {
// I'm not sure what to do at this point since I don't know how to pass the approvers as parameters to my script include. 
},
...

 

Glideajax works differently as it uses the xmlhttpprocessor (xmlhttp.do). The client side data is sent to the server with a http post to this endpoint and the script include object is constructed with the request as a property which is then accessed with getparameter.

 

The script include methods work just like named functions in this context