duplicate attachments in activity log

Peter Xiang
Tera Expert

Hi all,

 

I have created an Attachment field in the record producer, but after I upload the attachment, two records of the same attachment will appear in the ticket page. What is the reason for this? The HR module I use, There is a method in the record producer script: new sn_hr_core.hr_ServicesUtil(current, gs).createCaseFromProducer(producer, cat_item.sys_id);

Is the question related to this method?

 

PeterXiang_0-1690188987226.png

 

11 REPLIES 11

David Aldridge
Giga Guru

Do you need an "attachments field"? What happens if you just use the out of the box attachments functionality?

DavidAldridge_0-1699830231374.png

 

lffUnit4
Tera Contributor

Hi Experts!

 

I think I saw a correct answer previously but I can't seem to find it, so I'm reproducing it here.

This is expected behaviour according to servicenow KB: Attachment variable on record producer is duplicating attachements when submitting request - Known E...

 

As a workaround I've implemented a suggestion on the community to delete attachment on the variable that is "map to field". As a variable in a record producer the file is there on the record itself so we can have only one.

 

On the question_answer table, create a business rule to delete the attachment associated with the variable

lffUnit4_2-1756992577333.png

 

Condition:

(current.question.map_to_field && (current.question.type == 33)) 

Script:

(function executeRule(current, previous /*null when async*/ ) {(function executeRule(current, previous /*null when async*/ ) {
    var oldAttachSysId = current.value;

    //delete the attachment 
    var attGR = new GlideRecord('sys_attachment');
    attGR.get(oldAttachSysId);
    attGR.deleteRecord();

})(current, previous);

that successfully deletes the attachment on the variable.
When deleting the attachment we need to remove also the sys_attachment_doc table which has the binary data of the attachment. So I used GlideSysAttachment for that.

So this deletes the complete attachment data (less storage taken then).


Hope this helps someone.

 

Thank you.

Best!