Call script include from record producer script field

JJG
Kilo Guru

Hello,

I have a lengthy script that i need to run that I would like to place inside of a script include rather than the record producer script field. I need to call the script include and have access to the record producer variables from the script include. Here is what I have so far, it is not working yet:

Record Producer:

var callScriptInclude = new updateContractChangeField().contractChanges();

 

Script Include:

var updateContractChangeField = Class.create();
updateContractChangeField.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
   
	contractChanges: function(producer, current) {
        var contractName = producer.contract_name;
        gs.info('Contract Name: ' + contractName);
    },


    type: 'updateContractChangeField'
});

 

As you can see, I am trying to pull the contract_name variable from the producer. This is not working, the logs do not reflect the gs.info()

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

Your "contractChanges" function has the parameters in its declaration, but you are not passing them in from the RP script.  Try:

var callScriptInclude = new updateContractChangeField().contractChanges(producer, current);

Or if you are just dealing with 1 piece of data, just pass it instead of the whole "producer" object.  Like:

var callScriptInclude = new updateContractChangeField().contractChanges(producer.contract_name.toString(), current);

View solution in original post

7 REPLIES 7

Mike Patel
Tera Sage

try

var callScriptInclude = new updateContractChangeField().contractChanges(producer.contract_name);
var updateContractChangeField = Class.create();
updateContractChangeField.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
   
	contractChanges: function(producer) {
        var contractName = producer;
        gs.info('Contract Name: ' + contractName);
    },


    type: 'updateContractChangeField'
});

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi - Update script include call as below var callScriptInclude = new updateContractChangeField().contractChanges(producer.contract_name);

Script Include

var updateContractChangeField = Class.create();
updateContractChangeField.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
   
	contractChanges: function(cName) {
        var contractName = cName;
        gs.info('Contract Name: ' + contractName);
    },


    type: 'updateContractChangeField'
});

This works for one parameter, but I am going to be pulling 15 variables from my record producer (it is going to be a lengthy script). How can I do this?

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

The function in script include expecting 2 arguments, from the record producer script where you are calling the function, you are not passing anything.

-Anurag

-Anurag