How to Fix - Unable to save attachments to req/ritm using attachment variable from catalog on Portal

Vishal Jawalka1
Tera Expert

Synopsis 1 - Whenever we try to upload attachments using attachment variable, post creating a request it has to save the attachment in the RITM table. 

 

However, the file in the attachment table is created with prefix "ZZ_YYsc_cart_item", post request creation the table name might change to ZZ_YYsc_req_item.

 

To solve the above issues. 

a) you can exclude the anti-virus from the table. 

follow the below steps:

 

1. Go to dictionary, search for sc_cart_item table.

2. use collections column and open the record

3. under attributes, click new and create attribute to exclude_antivirus and set value as true.

4. clear cache and try if it works. 

 

b) if the above doesnt work, follow the below steps:

 

1. create an async BR on the target table.

2. use the below script and copy the attachment to the target table

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var gr = new GlideRecord("sys_attachment");
	gr.addQuery("table_name", "ZZ_YY" + current.getTableName());
	gr.addQuery("table_sys_id", current.sys_id);
	gr.query();
	if (gr.next()) {
		gr.table_name = current.getTableName();
		gr.update();
		new global.VariableUtil().copy(gr.sys_id, current.getTableName(), current.sys_id); 
	}

})(current, previous);

3. see if that works, if yes please thank Ankur.

 

Synopsis 2: We have been experiencing another type of issue while uploading attachment, which doesnt change the table name and stays in ZZ_YYsc_cart_item despite trying to fix the issue with the above remedies. 

 

if such issues occur, please try the below steps

 

1.  Create a before insert or after ( based on your requirement )  on target table.

2.  use the script ( my table is ritm table )

  var gr = new GlideRecord("sys_attachment");
        gr.addQuery("table_name", 'ZZ_YYsc_cart_item');
        gr.addQuery("sys_id", attachmentVariablename);
        gr.query();
        if (gr.next()) {
            gr.table_name = 'sc_request';
            gr.table_sys_id = current.request; (or current.sys_id for RITM )
           gr.update()
        }
        }
3. try the above, this will change the table name.
4. you can also copy the attachment using GlideSysAttachment() Api. 
 
note : the attachment variable saves the value of  sys_id of the attachment. so you can use this as connection to glide between attachment table and RITM/REQ table to copy attachment or update fields. 
 
0 REPLIES 0