How to delete an attachment thats added through an attachment variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2022 06:58 AM
Hi,
Using a attachment variable in a catalog form. Uploading an attachment through the upload button creates a record in sys_attachment table with the ZZ_YY notation in front of the table name. The delete button removes the file from the form but it leaves the uploaded file in the sys_attachment table. Uploading a new file, adds a new attachment to the sys_attachment table.
Documentation states "When you upload an attachment to this variable, an entry is created in the Attachment [sys_attachment] table. The variable is not updated until you submit the item request, add it to the cart, or save the record while editing it (in fulfiller flows). If you delete or update the attachment before submitting the corresponding catalog item, the entry in the Attachment [sys_attachment] table is cleared."
Well not for me. Anybody came with a solution for this.
Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2022 07:05 AM
i think the attachment will be cleared or deleted once you submit the catalog item
try submitting the item and try
please mark my answer correct if it helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2022 08:15 AM
No, they are left behind.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2022 08:19 AM
Solved it via an onchange client script on the attachment variable.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
alert("ID before setValue: " + g_form.getValue('version_file_id'));
var myOld = g_form.getValue('version_file_id');
g_form.setValue('version_file_id',newValue);
alert("ID after setValue: " + g_form.getValue('version_file_id'));
var myNew = g_form.getValue('version_file_id');
if (myOld) {
var ga = new GlideAjax('global.AttachmentAjax');
ga.addParam('sysparm_type','delete');
ga.addParam('sysparm_value',myOld);
ga.getXML(callBack);
}
}
function callBack(response) {
var comments = response.responseXML.documentElement.getAttribute("answer");
}
Maybe not the most beautiful, but it works. Open for suggestions on how to improve.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2023 11:02 PM - edited ‎06-15-2023 11:03 PM