Duplicate attachments are getting attached.

Mukesh Singh
Tera Contributor

Hi Everyone,

I have created a Record Producer where one variable type created as Attachment. When we are trying to attach documents through this, same document are getting attached 2 times.

On notes section on task record one document is showing blank and one document have correct data, However on attachment bar (top of the record) only one doc is showing and have no data.

 

If we are trying to attach the documents through attachment icon(out of the box), its working fine.

 

Please help me on this

1 ACCEPTED SOLUTION

Murthy Ch
Giga Sage

Hi @Mukesh Singh 

Gotchu!

Yes the attachments that are added to the attachment variable will only be displayed in notes section.

If you want to attach it to top of the record then you use below script. I have tried this a long back and it worked for me.

Create Async BR with high order and with high priority on table where record producer is created and give the correct conditions:

 

MurthyCh_1-1674529653893.png

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

    var gr = new GlideRecord("sc_item_produced_record");
    gr.addEncodedQuery("producer=ac2b37631b133010558d639bbc4bcbfb^record_table=incident^task=" + current.sys_id.toString()); // here replace with your record producer sys_id and replace with target table name where record is getting created
    gr.query();
    if (gr.hasNext()) {
        var abc = new GlideRecord('sys_attachment');
        abc.addQuery('table_name', 'ZZ_YY' + current.getTableName());
        abc.addQuery('table_sys_id', current.sys_id.toString());
        abc.query();
        while (abc.next()) {
            abc.table_name = current.getTableName();
            abc.update();
        }
    }


})(current, previous);

Let me know if you stuck any where

Happy to help:)

 

 

 

Thanks,
Murthy

View solution in original post

3 REPLIES 3

Murthy Ch
Giga Sage

HI @Mukesh Singh 

I think may be BR running on attachment table which is leading to creating the duplicate record.

Please check if any such BR's.

Thanks,
Murthy

Hi @Murthy Ch : I have noticed that previous developer had written below script in record producer to attach one more document because When documents were getting attached through "Attachment" type variable, its passing to target record but showing in notes section only not on the top of record.

 

But new attachment on the record don't have any data, its showing blank, Could you please review and suggest on this?

 

var gr = new GlideRecord('sys_attachment');
if(gr.get(producer.attachment)){
gr.table_name='idea';
gr.table_sys_id=current.sys_id;
gr.insert();

Murthy Ch
Giga Sage

Hi @Mukesh Singh 

Gotchu!

Yes the attachments that are added to the attachment variable will only be displayed in notes section.

If you want to attach it to top of the record then you use below script. I have tried this a long back and it worked for me.

Create Async BR with high order and with high priority on table where record producer is created and give the correct conditions:

 

MurthyCh_1-1674529653893.png

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

    var gr = new GlideRecord("sc_item_produced_record");
    gr.addEncodedQuery("producer=ac2b37631b133010558d639bbc4bcbfb^record_table=incident^task=" + current.sys_id.toString()); // here replace with your record producer sys_id and replace with target table name where record is getting created
    gr.query();
    if (gr.hasNext()) {
        var abc = new GlideRecord('sys_attachment');
        abc.addQuery('table_name', 'ZZ_YY' + current.getTableName());
        abc.addQuery('table_sys_id', current.sys_id.toString());
        abc.query();
        while (abc.next()) {
            abc.table_name = current.getTableName();
            abc.update();
        }
    }


})(current, previous);

Let me know if you stuck any where

Happy to help:)

 

 

 

Thanks,
Murthy