How to delete an attachment thats added through an attachment variable

Jan Post2
Tera Contributor

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

 

4 REPLIES 4

Mohith Devatte
Tera Sage
Tera Sage

@Jan Post  hello,

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

Jan Post2
Tera Contributor

No, they are left behind.

Jan Post2
Tera Contributor

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.

Clarkie1
Giga Expert

I had this same issue but eventually found a system property (glide.sc.variable.attachment.delete.v2) which when set to true resolved this issue for me, though this was on tokyo version and not Rome