attachement record procedure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 01:42 AM
Hello
i tried to attach the attachment in record procedure using incident form. not able to getting attached the attachment incident ticket
but not added in top of the incident
i used this script in inside script record procedure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 02:07 AM
Hello @sakila I would request you to update the spellings like attachment, record producer so that it will be clear as what you are looking for. Please use below script:
var incGR = new GlideRecord('incident');
incGR.initialize();
//Please add if there are more fields as per your requirement
incGR.short_description = current.short_description;
incGR.caller_id = gs.getUserID();
// Insert the new incident record
var incSysId = incGR.insert();
if (incSysId) {
// Check if there are any attachments uploaded with the record producer
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_name', current.getTableName());
attachmentGR.addQuery('table_sys_id', current.sys_id); // The sys_id of the record producer
attachmentGR.query();
// Loop through each attachment and attach it to the incident
while (attachmentGR.next()) {
var attachment = new GlideSysAttachment();
attachment.copy(attachmentGR, 'incident', incSysId); // Attach to the incident
}
// Showing confirmation message and recdirecting to incident created
gs.addInfoMessage('Incident created successfully: ' + incGR.number);
current.setRedirect(true);
} else {
gs.addErrorMessage('Failed to create incident.');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2024 03:12 AM
Hello,
Try to use the GlideSysAttachment API for handling attachments, here's a example about how to copy an attachment from an incident:
var attachment = new GlideSysAttachment();
var incidentSysID = 'ab1b30031b04ec101363ff37dc4bcbfc';
var incGR = new GlideRecord('incident');
incGR.get(incidentSysID);
var copiedAttachments = attachment.copy('incident', incidentSysID, 'problem', incGR.getValue('problem_id'));
gs.info('Copied attachments: ' + copiedAttachments);
Check this: https://docs.servicenow.com/bundle/vancouver-api-reference/page/app-store/dev_portal/API_reference/G...
☆ Community Rising Star 22, 23 & 24 ☆