Remove duplicate attachment from HR case

abirakundu23
Mega Sage

Hi All/ @Jaspal Singh 

I want to remove duplicate attachment from HR le case when HR service is "XYZ" . In HR case there are 2 HR tasks once 2nd task closed complete same attachment attached in HR life cycle case. 

Can someone please help me for that?

 

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@abirakundu23 Did you check if any business rule working on HR Task which on completion copies the attachment from task to case?

View solution in original post

4 REPLIES 4

Sandeep Rajput
Tera Patron
Tera Patron

@abirakundu23 Did you check if any business rule working on HR Task which on completion copies the attachment from task to case?

Hi @Sandeep Rajput ,

From case we want to remove duplicate attachment. How can we do use script for that ? 

There was a requirement but in case same attachment twice business raise a concern, we want to remove latest duplicate attachment from case. Please support me.

 

abirakundu23
Mega Sage

Hi @Sandeep Rajput / @Jaspal Singh ,

I wrote this below script on HR Life cycle table for before/insert. I want to if "Test HR Task " is closed complete then only it will be work. How can achieve ? Please help me on that, below code is not working.

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

    // Add your code here

var oldAttachSysId = current.value;

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

abirakundu23
Mega Sage

Hi All/ @Parag Kanoje@Danish Bhairag2 

 

 Even I tried this one as well as per other article , its not working.
Copy Attachments RITM to TASK & Task to RITM witho... - ServiceNow Community

 sys_attachment = remove duplicate attachments(before - insert, update) : 
script : 

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

    var attach = new GlideRecord('sys_attachment');
    attach.addQuery('table_sys_id', current.table_sys_id);
    attach.addQuery('table_name', current.table_name);
    attach.addQuery('file_name', current.file_name);
    attach.addQuery('content_type', current.content_type);
    attach.addQuery('size_bytes', current.size_bytes);
    attach.query();
    if (attach.next()) {
        current.setAbortAction(true);
    }

})(current, previous);
Quick support is really appreciate. Any suggestion.