Jaspal Singh
Mega Patron

Hi Rishabh,

Can you get the attachment copy line moved to the last line i.e. after current.update();

Additionally, why not show attachments as related list instead of copying attachments to target record. Link for additional reference.

Hello @Jaspal Singh Sir, I have advised them for the alternative approach similar as you advised but since they want closure of IMS record when Create Incident or Create request button clicked so that is why they want direct copy of attachments. (I have marked your shared link helpful).

Also I moved attachment copy line to the last line i.e. after current.update(); but still not working.

 

Requesting if possible for you to provide its solution

Please try below

GlideSysAttachment.copy('interaction', current.sys_id, 'sc_req_item', ritm.sys_id);

@Jaspal Singh Sir, I tried the modified script, it is not working as expected, same thing like a new REQ created along with RITM but attachment missed. I am continuously attaching attachment on IMS record but it did not copy the attachment to newly cretaed REQ

Currenly my UI Action Script and its configuration looks like:

 

createServiceRequest();
createM2M();

function createServiceRequest() {
    var cart = new Cart();
    var item = cart.addItem('d97d2beb97ae3110e6e3bb5ef053af85'); // sys_id of General request catalog item
    cart.setVariable(item, 'description', current.short_description);
    cart.setVariable(item, 'requested_for', current.opened_for);
    var cartGR = cart.getCart();
    cartGR.requested_for = current.opened_for;
    cartGR.update();
    var newSerReq = cart.placeOrder();
    newSerReq.opened_by = current.opened_for;
    newSerReq.update();
    current.parent = getRITM(newSerReq.sys_id);
    current.update();
    var disMessage = 'Interaction ' + current.number + ' has been converted into Service Request ' + newSerReq.number;
    gs.addInfoMessage(disMessage);
    action.setRedirectURL(newSerReq);
    action.setReturnURL(current);
}

function getRITM(serReq) {
    var ritm = '';
    var grRITM = new GlideRecord('sc_req_item');
    grRITM.addQuery('request', serReq);
    grRITM.query();
    if (grRITM.next()) {
        ritm = grRITM.sys_id;
    }
    return ritm;
}

function createM2M(grRITM) {
    var gr = new GlideRecord('interaction_related_record');
    gr.newRecord();
    gr.document_table = 'sc_req_item';
    gr.interaction = current.sys_id;
    gr.document_id = grRITM.sys_id();
    //gr.task = grRITM.sys_id();
    gr.type = 'task';
    gr.insert();

	
	//'interaction', current.interaction, 'sc_req_item', ritm.sys_id
}
/*When Create Request button clicked from respective IMS record, then State of IMS sets to 'Closed Complete' and 
worknotes populated as 'Request created'*/
current.state = "closed_complete"; // add closed state value
current.work_notes = "Request created";
current.update();

//GlideSysAttachment.copy('interaction', current.interaction, 'sc_req_item', ritm.sys_id);
GlideSysAttachment.copy('interaction', current.sys_id, 'sc_req_item', ritm.sys_id);

 

rishabh31_0-1714381981792.png

That will be great if you can try this in your PDI.

 

Thanks 

rishabh31
Mega Sage

Can anyone please help on this!