Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Remove prefix from table name in sys_attachment table

Nishant26
Tera Contributor

Hi @Ankur Bawiskar ,

 

I need to update the attachment from record producer to the incident table form. I am seeing "ZZ_YY" prefix in the table name field on the sys_attachment" table. this is causing the error while executing the code. 

Here is the code: 

 

var gr = new GlideRecord('sys_attachment');
if(gr.get(producer.number_list)){ //attachment field name
    gr.table_name='incident';     //copy to table name
    gr.table_sys_id=current.sys_id;//copy to record sys_id
    gr.update();
    
}
 
I need to remove the prefix "ZZ_YY" from the table name field in the sys_attachment table. how can this be achieved.
 
Thanks!
1 ACCEPTED SOLUTION

@Nishant26 

can you try this code?

I have commented this line

// new global.VariableUtil().copyAttachment(gr.sys_id, current.getTableName(), current.sys_id);

(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);

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

View solution in original post

17 REPLIES 17

Hi @Ankur Bawiskar - Do you know why this line of code is removed 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

@kevindang 

Can you post a new question and share all the details there and tag me there as this is an old thread?

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