GlideSysAttachment.copy function

Chad31
Mega Expert

I have a requirement to create a facilities request from within a workflow on a catalog item. Part of this is to have the attachments from the RITM be copied on to the facilities request that is created. 

I have used the glidesysattachment.copy function, one that we use on a UI action to do something similar and it wont copy over the attachments. Are attachments from RITMS from an order guide on a different table than the sc_req_item table? Not sure where I am going wrong here.

Below is my script, this is via a run script on the workflow on the sc_req_item table.  Any help is greatly appreciated. 

var fr = new GlideRecord("facilities_request");
fr.opened_for = current.reques.requested_for.getDisplayValue();
fr.assignment_group.setDisplayValue('Corporate Security');
fr.contact_type = 'self-service';
fr.category = 'security';
fr.requested_due_by = current.variables.requested_due_by;
fr.short_description = 'ID Badge (New) - Onboarding';
fr.description = 'ID Badge (New or Modify access) - Onboarding for ' + current.request.requested_for.getDisplayValue() + '\n' + current.variables.description;
u_confidential_record = false;

fr.work_notes = '\nTYPE: ' + current.variables.type.getDisplayValue()+
	'\nREQUESTED FOR: ' + current.request.requested_for.getDisplayValue()+
	'\nREQUESTED FOR MANAGER: ' + current.request.requested_for.manager.getDisplayValue()+
	'\nSUBMITTED BY: ' + current.opened_by.getDisplayValue()+
	'\nPRIORITY: ' + current.variables.priority.getDisplayValue()+
	'\nREQUEST DUE BY: ' + current.variables.requested_due_by;
var sysID = fr.insert();


//Pull attachments from RITM to FCR
GlideSysAttachment.copy('sc_req_item', current.sys_id, 'facilities_request', sysID);
6 REPLIES 6

Chad31
Mega Expert

Anybody have suggestions on this. Still unable to figure it out and it's driving me crazy, any help is appreciated. Thank you. 

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,

 

See below code:

var fr = new GlideRecord("facilities_request");
fr.initialize(); //You have to initialize first
fr.opened_for = current.reques.requested_for.getDisplayValue(); fr.assignment_group.setDisplayValue('Corporate Security');
fr.contact_type = 'self-service'; fr.category = 'security';
fr.requested_due_by = current.variables.requested_due_by;
fr.short_description = 'ID Badge (New) - Onboarding';

fr.description = 'ID Badge (New or Modify access) - Onboarding for ' + current.request.requested_for.getDisplayValue() + '\n' + current.variables.description; u_confidential_record = false; fr.work_notes = '\nTYPE: ' + current.variables.type.getDisplayValue()+ '\nREQUESTED FOR: ' + current.request.requested_for.getDisplayValue()+ '\nREQUESTED FOR MANAGER: ' + current.request.requested_for.manager.getDisplayValue()+ '\nSUBMITTED BY: ' + current.opened_by.getDisplayValue()+ '\nPRIORITY: ' + current.variables.priority.getDisplayValue()+ '\nREQUEST DUE BY: ' + current.variables.requested_due_by;

var sysID = fr.insert(); //Pull attachments from RITM to FCR
GlideSysAttachment.copy('sc_req_item', current.sys_id, 'facilities_request', sysID);


Thanks,

Ashutosh Munot

 

Please Hit Correct, Helpful or like,if you are satisfied with this response.

Thank you for the response. The problem is not that the facilities request isn't getting generated. The problem is the attachment is not copying over from the RITM that the workflow is ran on. 

I used the fr.initialize you suggested just in case and experienced the same behavior. 

Chad31
Mega Expert

I've tried changing the tables around and transferring from an RITM to a TASK as a test and it still doesn't work. Can the GlideSysAttachment.copy function work through runscripts on workflows?