attachment is not copied when i click on copy change option in case of normal change(change management).

Nikita Singh
Giga Expert

Hi,

Attachment is not getting copied along with other fields when i am clicking on copy change option in case of normal change(change management). Even i have ticked enable copy change feature but still it's not working.

find_real_file.png

Pls help

1 ACCEPTED SOLUTION

Hi Nikita,

in the out of the box Copy Change UI action it is calling a script include ChangeUtils

below is the out of the box code

function OnCopyChangeClick() {
function addParam(form, name, val) {
var inp = cel('textarea', form);
inp.name = name;
inp.value = val;
}

var srcSysId = g_form.getUniqueValue(); // this is the source record sys_id

var ga = new GlideAjax('ChangeUtils');
ga.addParam('sysparm_name', 'getChangeQueryParams');
ga.addParam('sysparm_src_sysid', srcSysId);
ga.setWantSessionMessages(true);
ga.getXMLAnswer(function (queryParam) {
if (queryParam) {
var gotoURL = new GlideURL('CopyChangeRelatedLists.do');
gotoURL.setEncode(false);
gotoURL.addToken();
gotoURL.addParam('srcSysID', srcSysId);
gotoURL.addParam('newSysID', '$sys_id'); // this is the new target record sys_id
gotoURL.addParam('sysparm_returned_action', '$action');

var form = cel('form', document.body);
hide(form);
form.method = "POST";
form.action = g_form.getTableName() + ".do";
if (typeof g_ck != 'undefined' && g_ck != "")
addParam(form, 'sysparm_ck', g_ck);
addParam(form, 'sys_id', '-1');
addParam(form, 'sysparm_query', queryParam);
addParam(form, 'sysparm_goto_url', gotoURL.getURL());
form.submit();
}
});
}

just check when new change is created as copy of older; does it fill the parent field with the old change number

if yes then have after insert BR on change request with condition as parent is not empty

GlideSysAttachment.copy('change_request', current.parent, 'change_request', current.sys_id);

what it will do is copy attachments from parent record to new record

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Omkar Mone
Mega Sage

Hi 

In the UI Action try adding this line - 

GlideSysAttachment.copy('change_request', chgID, 'change_request', newChange.sys_id);

 

Hope this helps

 

Regards,

Omkar Mone

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Check whether in that UI action you have code for copy attachment?

I don't think it exist out of the box

check the UI action code and put this code below

GlideSysAttachment.copy('change_request', current.sys_id , 'change_request', newSysId);

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

 

Thanks for your reply but it's still not working.

Hi Nikita,

in the out of the box Copy Change UI action it is calling a script include ChangeUtils

below is the out of the box code

function OnCopyChangeClick() {
function addParam(form, name, val) {
var inp = cel('textarea', form);
inp.name = name;
inp.value = val;
}

var srcSysId = g_form.getUniqueValue(); // this is the source record sys_id

var ga = new GlideAjax('ChangeUtils');
ga.addParam('sysparm_name', 'getChangeQueryParams');
ga.addParam('sysparm_src_sysid', srcSysId);
ga.setWantSessionMessages(true);
ga.getXMLAnswer(function (queryParam) {
if (queryParam) {
var gotoURL = new GlideURL('CopyChangeRelatedLists.do');
gotoURL.setEncode(false);
gotoURL.addToken();
gotoURL.addParam('srcSysID', srcSysId);
gotoURL.addParam('newSysID', '$sys_id'); // this is the new target record sys_id
gotoURL.addParam('sysparm_returned_action', '$action');

var form = cel('form', document.body);
hide(form);
form.method = "POST";
form.action = g_form.getTableName() + ".do";
if (typeof g_ck != 'undefined' && g_ck != "")
addParam(form, 'sysparm_ck', g_ck);
addParam(form, 'sys_id', '-1');
addParam(form, 'sysparm_query', queryParam);
addParam(form, 'sysparm_goto_url', gotoURL.getURL());
form.submit();
}
});
}

just check when new change is created as copy of older; does it fill the parent field with the old change number

if yes then have after insert BR on change request with condition as parent is not empty

GlideSysAttachment.copy('change_request', current.parent, 'change_request', current.sys_id);

what it will do is copy attachments from parent record to new record

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader