Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Auto create a change request based on a catalog task??

Reddy
Kilo Sage

Hello,

 

I've a requirement where I need to automatically create a change request from a catalog task. I've a catalog task in a workflow named 'change request catalog task'. On this task I'm asking assigned to user to Input below fields 

Reddy_0-1692321001834.png

 

Reddy_1-1692321028045.png

 

var chg = new GlideRecord ("change_request");
chg.initialize();
chg.applyTemplate("Normal Change");
chg.short_description = current.variables.short_description;
chg.description = current.variables.description;
chg.justification = current.variables.description;
chg.u_auto_created = 'true';
//chg.work_notes = "This changes request was created part of" + gr.number ;
chg.parent=current.sys_id;
chg.cab_date = task.u_cab_date;
var id=chg.insert();
var gr=new GlideRecord ("change_request");
gr.get(id);
current.comments="Normal Change " + gr.number + " has been created";

 

Once the above fields are updated I need to automatically create a change request and Once the associated change request is closed, I need to close the 'change request catalog task'

 

1 ACCEPTED SOLUTION

varaprasad123
Kilo Guru

Try modify the following script according to your need.

 

(function execute() {
// Get the current Catalog Task record
var currentTask = new GlideRecord('sc_task');
if (currentTask.get(current.sys_id)) {
// Create a new Change Request record
var changeReq = new GlideRecord('change_request');
changeReq.initialize(); // Initialize a new record

// Map fields from the Catalog Task to the Change Request
changeReq.short_description = currentTask.short_description;
changeReq.description = currentTask.description;
// Map other relevant fields...

// Set the change type, urgency, impact, etc.
changeReq.change_type = 'Standard'; // Change type example
changeReq.urgency = currentTask.urgency;
changeReq.impact = currentTask.impact;

// Set the assignment group and assigned to based on your logic
changeReq.assignment_group = currentTask.assignment_group;
changeReq.assigned_to = currentTask.assigned_to;

// Insert the Change Request record
var changeReqSysID = changeReq.insert();
if (changeReqSysID) {
gs.log('Change Request ' + changeReqSysID + ' created from Catalog Task ' + currentTask.number);
} else {
gs.error('Failed to create Change Request from Catalog Task ' + currentTask.number);
}
}
})();

View solution in original post

3 REPLIES 3

varaprasad123
Kilo Guru

Try modify the following script according to your need.

 

(function execute() {
// Get the current Catalog Task record
var currentTask = new GlideRecord('sc_task');
if (currentTask.get(current.sys_id)) {
// Create a new Change Request record
var changeReq = new GlideRecord('change_request');
changeReq.initialize(); // Initialize a new record

// Map fields from the Catalog Task to the Change Request
changeReq.short_description = currentTask.short_description;
changeReq.description = currentTask.description;
// Map other relevant fields...

// Set the change type, urgency, impact, etc.
changeReq.change_type = 'Standard'; // Change type example
changeReq.urgency = currentTask.urgency;
changeReq.impact = currentTask.impact;

// Set the assignment group and assigned to based on your logic
changeReq.assignment_group = currentTask.assignment_group;
changeReq.assigned_to = currentTask.assigned_to;

// Insert the Change Request record
var changeReqSysID = changeReq.insert();
if (changeReqSysID) {
gs.log('Change Request ' + changeReqSysID + ' created from Catalog Task ' + currentTask.number);
} else {
gs.error('Failed to create Change Request from Catalog Task ' + currentTask.number);
}
}
})();

Hello @varaprasad123,

 

Thank you for your response!

 

The script is working as intended, but our change request's has 'Request for approval' UI action, sends the request for approval when clicked. How do I call the UI action in the script mentioned above?

 

After the auto created change is closed how do I close the catalog task automatically?

 

xjxx
Tera Contributor

Did you manage to solve it?

For requirement 1, I think this should be invoked as part of "after creation" business rule action/scripts.

For requirement 2, I think you can do same script when CRQ is closed to revert back and close the Task/request.

Not sure actually about my advice it will work, but those can be one of the available options.