Attachment in GlideRecord

Andrew112
Kilo Guru

Hello.. I'm trying to copy an attachment to the new change request in the below glide script, it is not working please help... to be specific I want the attachment to pull from the current record to the new record being created in the GlideRecord

 

var gr = new GlideRecord('change_request');
gr.initialize();
gr.u_rfc_number = current.sys_id;
gr.requested_by = current.u_requested_by;
gr.business_service = current.business_service;
gr.u_chg_line_manager = current.u_line_manager;
gr.cmdb_ci = current.cmdb_ci;
gr.category = current.u_category;
gr.reason = current.u_reason;
gr.priority = current.priority;
gr.impact = current.impact;
gr.risk = current.u_risk;
gr.assignment_group = current.assignment_group;
gr.assigned_to = current.assigned_to;
gr.watch_list = current.watch_list;
gr.work_notes_list = current.work_notes_list;
gr.short_description = current.short_description;
gr.description = current.description;
gr.justification = current.u_justification;
gr.impmentation_plan = current.u_implementation_plan;
gr.risk_impact_analysis = current.u_risk_and_impact_analysis;
gr.backout_plan = current.u_backout_plan;
gr.test_plan = current.u_test_plan;
gr.start_date = current.u_planned_start_date;
gr.end_date = current.u_planned_end_date;
gr.state = '-4';
gr.insert();

GlideSysAttachment.copy('u_req_for_change', current.sys_id, 'change_request', gr.insert());
2 REPLIES 2

Sagar Pagar
Tera Patron

Hi @Andrew112,

Try this updated scripts -

 

var gr = new GlideRecord('change_request');
gr.initialize();
gr.u_rfc_number = current.sys_id;
gr.requested_by = current.u_requested_by;
gr.business_service = current.business_service;
gr.u_chg_line_manager = current.u_line_manager;
gr.cmdb_ci = current.cmdb_ci;
gr.category = current.u_category;
gr.reason = current.u_reason;
gr.priority = current.priority;
gr.impact = current.impact;
gr.risk = current.u_risk;
gr.assignment_group = current.assignment_group;
gr.assigned_to = current.assigned_to;
gr.watch_list = current.watch_list;
gr.work_notes_list = current.work_notes_list;
gr.short_description = current.short_description;
gr.description = current.description;
gr.justification = current.u_justification;
gr.impmentation_plan = current.u_implementation_plan;
gr.risk_impact_analysis = current.u_risk_and_impact_analysis;
gr.backout_plan = current.u_backout_plan;
gr.test_plan = current.u_test_plan;
gr.start_date = current.u_planned_start_date;
gr.end_date = current.u_planned_end_date;
gr.state = '-4';
var targetId = gr.insert();

var copyAtt = new GlideSysAttachment();
copyAtt.copy('u_req_for_change',current.getUniqueValue(), 'change_request', targetId);

 

 

Thanks,

Sagar Pagar

The world works with ServiceNow

nope... not copying it.