Copy Change UI action without copying the change tasks

Anna Gausel
Giga Expert

We have a requirement to stop the OOB Copy change UI Action from copying change tasks, as the tasks get triggered naturally through the change workflow.

Looking at the 'Copy Change' UI action script - it does not refer to the copying of tasks. The script include called in the UI Action -  'ChangeUtils' also does not refer to copying the tasks. I've also checked Change Properties and there is nowhere to disable the copying of change tasks.

I've located a community thread with instructions to created a new UI action for copy change. I've used this as a basis to create my own UI action but the condition 'gs.hasRole(“itil”) && current.isValidRecord()' did not work. Mine is as follows, but for some reason it is also still copying tasks:

Onclick: OnCopyChangeClick()

Condition:  gs.hasRole('itil')&&ChangeUtils.isCopyChangeEnabled(current)

Script:

var chgID = current.sys_id.toString();
var newChange = new GlideRecord('change_request');
newChange.initialize();
//copy existing change fields
newChange.short_description = current.short_description;
newChange.requested_by = current.requested_by;
newChange.category = current.category;
//newChange.business_service = current.business_service; not creating have created new function
newChange.type = current.type;
newChange.assignment_group = current.assignment_group;
newChange.assigned_to = current.assigned_to;
newChange.description = current.description;
newChange.risk = current.risk;
newChange.urgency = current.urgency;
newChange.reason = current.reason; //is not copying
newChange.justification = current.justification; //is not copying
newChange.implementation_plan = current.implementation_plan; //is not copying
newChange.risk_impact_analysis = current.risk_impact_analysis; //is not copying
newChange.test_plan = current.test_plan;
newChange.backout_plan = current.backout_plan;
newChange.u_will_this_change_cause_downtime = current.u_will_this_change_cause_downtime;
newChange.u_is_this_change_related_to_a_project = current.u_is_this_change_related_to_a_project; //is not copying
newChange.insert();

//Copy attachments for this change
if (typeof GlideSysAttachment != 'undefined')
   GlideSysAttachment.copy('change_request', chgID, 'change_request', newChange.sys_id);
else
   Packages.com.glide.ui.SysAttachment.copy('change_request', chgID, 'change_request', newChange.sys_id);
//copyTask();
copyCI();
copyService();
gs.addInfoMessage('Change ticket ' + newChange.number + ' created.');
action.setRedirectURL(newChange);


function copyCI() {
//Copy over the affected CI list
var currentCI = new GlideRecord('task_ci');
currentCI.addQuery('task', current.sys_id);
currentCI.addNullQuery('u_ci_group'); //Added to ensure that copying does not duplicate Group CIs
currentCI.query();
while(currentCI.next()){
var newCI = new GlideRecord('task_ci');
newCI.initialize();
newCI.task = newChange.sys_id;
newCI.ci_item = currentCI.ci_item;
newCI.insert();
}
}

//copy the current business service
function copyService() {
var currentService = new GlideRecord('cmdb_ci_service');
currentService.addQuery('name', current.sys_id);
currentService.query();
while(currentService.next()){
var newService = new GlideRecord('cmdb_ci_service');
newService.initialize();
newService.name = newChange.sys_id;
newService.cmdb_ci_service = currentService;
newService.insert();
}}

Any ideas?

Many thanks,

Anna

1 ACCEPTED SOLUTION

kristenankeny
Tera Guru

Try finding this property and remove the change tasks: com.snc.change_request.copy.related_lists

View solution in original post

6 REPLIES 6

kristenankeny
Tera Guru

Try finding this property and remove the change tasks: com.snc.change_request.copy.related_lists

Awesome - thanks that's done the trick 🙂

Strange that the correct answer isn't marked as such.

Thanks, this solution worked.

Thanks Phonsie, corrected that 😉