- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2023 02:48 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2023 07:58 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2023 03:57 AM
@Vinay49 This is how you should call your script include inside the BR.
var company_creation = new c_ComapnyAutoTaskUtil(current.request_item).processCompanyCreation();
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2023 06:14 AM
Hi Sandeep,
Thanks for your reply,
I have used the same in the BR & script include was getting excuted & company is created. However, where the variables values are setting those lines are not excuted.
Ex:
grCompany.name = this.reqItemObj.variables.u_customer.u_kvk_name;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2023 06:41 AM
i have updated BR like below.
var reqItem = current.request_item;
var company_creation = new c_ComapnyAutoTaskUtil(reqItem).processCompanyCreation();
This time company has created with the variable values. But sc_task has not updated.i.e below line not excuted
grScTask.addQuery('request_item', this.reqItemObj.getUniqueValue());

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2023 07:28 AM
@Vinay49 can you log value of
gs.info(this.reqItemObj.getUniqueValue());
and check if it is printing correct sys_id?
Also, do you have script include CatalogTaskState on your instance? As it is being referred for getting the closed complete state CatalogTaskState.CLOSED_COMPLETE.
Try setting the state like following.
grScTask.state = '3'; //Closed Complete
Hope this helps.