Copy attachment from Order guide to REQ/RITMS

Pintu2
Tera Expert

I have a  attachment variable on the order guide and I want to copy the attachment from order guide to REQ and also related RITM's.

Currently if I add attachment i can't see the file on REQ/RITMS (except on sys_attachment table). How to pass this attachment file to REQ## and then to RITMS.

 

1 ACCEPTED SOLUTION

Pintu2
Tera Expert

I tried enabling Cascading option and create same variable type on other catalog items that I want to carry forward.

View solution in original post

3 REPLIES 3

John Dahl
Tera Guru

The GlideSysAttachment API (GlideSysAttachment Docs) has a method called copy that will copy all of the attachments from one record to another. If you don't mine ALL of the attachments being copied over, that will be the easiest solution for you.

I'm not a fan of this for your use case because I don't like leaving copies of files around where they are not required. I would prefer to simply move the attachment to where it's required. I would do something like the sample below.

var sourceTableName = 'WHATEVER_THE_ORDERGUIDE_TABLE_IS';
var sourceRecordID = 'ORDER_SYS_ID';

var targetTableName = 'REQ/RITM_TABLE_NAME';
var targetRecordID = 'REQ/RITM_SYS_ID';

var grAttach = new GlideRecord( 'sys_attachment' );
grAttach.addQuery( 'table_name', sourceTableID );
grAttach.addQuery( 'table_sys_id', sourceRecordID );
grAttach.query();

if( grAttach.next() ){
  grAttach.setValue( 'table_name', targetTableName );
  grAttach.setValue( 'table_sys_id', targetRecordID );

  gr.update();
}

 

 

 

I tried on After -Insert BR on sc_request table. Its not working :

I want to copy the attachment from order guide to REQ in first go-

var attachment = new GlideSysAttachment();

var catalogItemSysID = 'e31dcbc21b37c1149547da03b24bcb36';
var catalogTaskSysId = 'e336a87a1bbb4150c28c54a3604bcb54';

var sourceTable = 'sc_cat_item_guide';
var targetTable = 'sc_request';

var copiedAttachments = attachment.copy(sourceTable, catalogItemSysID, targetTable, catalogTaskSysId);

Pintu2
Tera Expert

I tried enabling Cascading option and create same variable type on other catalog items that I want to carry forward.