How to pass parameters from BR to initialize function() in script include

Vinay49
Tera Expert

Hello all,

We have one catalog item for the company creation & when user raise request under this catalog item task will be created & assigned as of now. So that assignee will manually create the company on core_company table.Now the requirement is, we have to automate this process. for this we have one existing script include(pasted below). we just want to use the same without touching workflow.

 

var c_ComapnyAutoTaskUtil = Class.create();
c_ComapnyAutoTaskUtil.prototype = {
initialize: function(reqItem) {
this.reqItemObj = reqItem;
},
processCompanyCreation: function() {
processedMessage = '';
//Company creation
var grCompany = new GlideRecord('core_company');
grCompany.initialize();
grCompany.name = this.reqItemObj.variables.u_customer.u_kvk_name;
grCompany.active = true;
grCompany.u_migrated = true;
grCompany.insert();
processedMessage += '\nCompany added successfully';
//Update the catalog task
this._updateTask(processedMessage);
},

_updateTask: function(processedMessage) {
var grScTask = new GlideRecord('sc_task');
grScTask.addQuery('request_item', this.reqItemObj.getUniqueValue());
grScTask.query();
if (grScTask.next()) {
grScTask.close_notes = processedMessage;
grScTask.state = CatalogTaskState.CLOSED_COMPLETE;
grScTask.update();
}
},

type: 'c_ComapnyAutoTaskUtil'
};

 

What i did;

 

on sc_task table created one after insert BR with satisfied conditions & added this script include & function in the advanced section like below.

     var company_creation = new c_ComapnyAutoTaskUtil.processCompanyCreation();

However, it is not working. something i am missing here to pass the request item(from task table) value into initialize function in script include. Your help will be appreciated here

 

Thanks in Advance

1 ACCEPTED SOLUTION

Amit Gujarathi
Giga Sage
Giga Sage

Hi @Vinay49 ,
I trust you are doing great.
To pass the request item value into the initialize function, you'll need to modify your after insert business rule on the sc_task table. In the advanced section, you'll want to create a new instance of the c_ComapnyAutoTaskUtil object and pass the request item object as a parameter. Here's an example of what that might look like:

var reqItem = new GlideRecord('sc_req_item');
if (reqItem.get(current.request_item)) {
  var companyAutoTaskUtil = new c_ComapnyAutoTaskUtil(reqItem);
  companyAutoTaskUtil.processCompanyCreation();
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



View solution in original post

7 REPLIES 7

Hi @Sandeep Rajput,

 

I did log of below & it print as undefined.

 

gs.info('Unique value:'+this.reqItemObj.getUniqueValue());

 

Also, we have script include CatalogTaskState on my instance.

 

Amit Gujarathi
Giga Sage
Giga Sage

Hi @Vinay49 ,
I trust you are doing great.
To pass the request item value into the initialize function, you'll need to modify your after insert business rule on the sc_task table. In the advanced section, you'll want to create a new instance of the c_ComapnyAutoTaskUtil object and pass the request item object as a parameter. Here's an example of what that might look like:

var reqItem = new GlideRecord('sc_req_item');
if (reqItem.get(current.request_item)) {
  var companyAutoTaskUtil = new c_ComapnyAutoTaskUtil(reqItem);
  companyAutoTaskUtil.processCompanyCreation();
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Hi Amit,

 

it is working as expected now after updated the BR with the script shared by you

 

Thanks .