Attachment from cat item is not carried over to the table where a record is inserted via workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 04:35 PM - edited 05-09-2024 04:36 PM
Hi!
We have a catalog item in the portal which also creates an incident record based on the selected value in a field.
For example if the Request type= Incident, an incident record should be submitted. If the Request type=Request, it should create the usual process wherein it has Request>RITM>Sctask
The problem is that when Request type= Incident, the attachment attached in the portal, when submitted, the incident record has no attachment/ it did not carried over the attachment from the portal.
I checked the sys_attachment table and the attachment was under the sc_req_item instead of incident. How can we fix this?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2024 05:49 PM - edited 05-09-2024 05:52 PM
Hi @ss123 ,
Please try the below code snippet to solve the issue.
If incidents are getting created from requested item then follow the below config-
if (current.request_type == 'incident') {
// Create a new incident record
var inc = new GlideRecord('incident');
inc.initialize();
inc.short_description = current.short_description;
inc.description = current.description;
inc.caller_id = current.requested_for;
inc.insert();
// Copy attachments
GlideSysAttachment.copy('sc_req_item', current.sys_id, 'incident', inc.sys_id);
}
Note: Here we are considering that the incident is getting created based on RITM
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2024 06:11 PM - edited 05-12-2024 06:38 PM
Hi @Community Alums , I tried to use the script below but it still not getting the attached document from the RITM
// Copy attachments GlideSysAttachment.copy('sc_req_item', current.sys_id, 'incident', inc.sys_id);
Here's our actual script on the workflow. Maybe I'm placing it on the wrong line?
var gr = new GlideRecord('incident');
gr.initialize();
gr.short_description = current.variables.please_select_application.getDisplayValue() + ': ' + current.variables.issue_request_type.getDisplayValue() + ' | ' + current.variables.short_description;
gr.category = 'application';
///gr.assignment_group = '5c046272dbcf285083215843e2961930';
gr.assignment_group = 'f26217851bbcb300461376e1dd4bcb70';
gr.caller_id = current.variables.itsm_requested_by;
gr.u_open_for = current.variables.itsm_requested_for;
gr.description = 'Client: \n' + current.variables.client + '\n\nPlease describe your issue / request below:\n' + current.variables.please_describe_your_issue_request_below_gipm + current.variables.please_describe_your_issue_request_below + current.variables.please_describe_your_issue_request_below_bipc + current.variables.please_describe_your_issue_request_below_fft + current.variables.please_describe_your_issue_request_below_maps;
gr.watch_list = current.variables.please_add_any_additional_recipients_for_completion_email_if_applicable;
//'sys_id'+ ',' +
var urg = current.variables.itsm_urgency;
var app = current.variables.please_select_application;
if (urg == 'high')
gr.urgency = '1';
else if (urg == 'medium')
gr.urgency = '2';
else
gr.variables.urgency = '3';
if (app == '5e14a42f1b9f7014f2e51fc58d4bcb31') //GIPM
gr.cmdb_ci = '5e14a42f1b9f7014f2e51fc58d4bcb31';
else if (app == 'd214a42f1b9f7014f2e51fc58d4bcb30') //BIPC
gr.cmdb_ci = 'd214a42f1b9f7014f2e51fc58d4bcb30';
else if (app == '5614a42f1b9f7014f2e51fc58d4bcb33') // MAPS
gr.cmdb_ci = '5614a42f1b9f7014f2e51fc58d4bcb33';
else if (app == '1214a42f1b9f7014f2e51fc58d4bcb31') // FFT
gr.cmdb_ci = '1214a42f1b9f7014f2e51fc58d4bcb31';
else if (app == '9614a42f1b9f7014f2e51fc58d4bcb2f') // AFFT
gr.cmdb_ci = '9614a42f1b9f7014f2e51fc58d4bcb2f';
else if (app == 'c714e42f1b9f7014f2e51fc58d4bcb83') //IPM
gr.cmdb_ci = 'c714e42f1b9f7014f2e51fc58d4bcb83';
gr.contact_type = ' self-service';
gr.parent = current.getUniqueValue(); // Attaches incident to Request item helps in tracking
gr.setWorkflow(false);
// Copy attachments
GlideSysAttachment.copy('sc_req_item', current.sys_id, 'incident', gr.sys_id);
gr.insert();
current.short_description = "IPSU Applications : Please refer to the Incident";
current.description = "Please refer to " + gr.number;
var grRequest = new GlideRecord('sc_request');
grRequest.get(current.request);
//set request values
grRequest.short_description = current.short_description;
grRequest.description = "Please refer to " + gr.number;
grRequest.update();
/*var gr_task = new GlideRecord('incident_task');
gr_task.initialize();
gr_task.incident = gr.sys_id;
gr_task.short_description = current.variables.please_select_application.getDisplayValue() + ': ' + current.variables.issue_request_type.getDisplayValue() + ' | ' + current.variables.short_description;
gr_task.assignment_group = '5c7492f21bbe04d0b0ceda48cc4bcb85';
gr_task.cmdb_ci = gr.cmdb_ci;
gr_task.setWorkflow(false);
gr_task.insert();
*/
///workflow.scratchpad.incnumber = gr.number;
current.variables.incident_number = gr.number;
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2024 07:02 PM
Hi @Community Alums
Maybe this can help but upon checking the incident created from an RITM has a field which refers to the originated RITM.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2024 10:40 AM
Hi @ss123 ,
I believe the issue is with the below line of code where you are trying to copy the attachment
Here you are trying to copy the attachment without having the sys_id of the incident.
Before insert how can you get the sys_id of a recored, thats the reason.
gr.setWorkflow(false);
// Copy attachments
GlideSysAttachment.copy('sc_req_item', current.sys_id, 'incident', gr.sys_id);
gr.insert();
Please replace the above code with the new code provided below-
gr.setWorkflow(false);
var newIncidentId = gr.insert();
if (newIncidentId) {
// Copy attachments from the catalog item to the newly created incident
var copied = GlideSysAttachment.copy('sc_req_item', current.sys_id, 'incident', newIncidentId);
}
here we are capturing the newly created incident sys_id and then copying the attachment.
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar