Follow-up question - Remove prefix from table name in sys_attachment table

kevindang
Tera Contributor

Hi @Ankur Bawiskar.

This is just a follow-up question regarding the script below you posted in https://www.servicenow.com/community/itsm-forum/remove-prefix-from-table-name-in-sys-attachment-tabl.... You asked me to created a new post since this was an old thread.

(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().copyAttachment(gr.sys_id, current.getTableName(), current.sys_id); 
    }

})(current, previous);

Do you know why this line of code is commented for "sc_req_item" table and the attachments still show up on attachment list on top of the record whereas the same line of code needs to be added for "sn_hr_core_case" table for the same reason? Thanks

 

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@kevindang 

the commented code was possibly used to avoid duplicate file.

check this link where I shared solution on how to copy file from attachment type variable to target record on form

Disable ZZ_YY prefix from attachment when added through record producer 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

kevindang
Tera Contributor

@Ankur Bawiskar - That's correct. But why is it duplicated on "sc_req_item" table and not on "sn_hr_core_case" table with the commented code?

@kevindang 

when I shared the earlier solution and when I wrote the blog recently, it didn't duplicate the file on target record

check this blog

Copying Attachments from a Record Producer's Attachment Variable to a Target Record in ServiceNow 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

kevindang
Tera Contributor

Hi @Ankur Bawiskar - Thanks for sharing another way to copy the attachment in above post. I disabled the Business Rule and tried this record producer script on "sn_hr_core_case_relations" table, which is extended from "sn_hr_core_case", but it still shows duplicate copies of the attachment under Activity stream as seen in the attached screenshot.Duplicate_Attachments.png