Business rule to insert attachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 04:00 AM
I have a requirement here. If anybody could guide that would be of great help.
I need to copy attachment from a Requested Item and then insert that attachment to a data source.
This has to happen for a specific Item (i.e.) (If I am requesting apple iPad catalog item and adding a attachment to it the business rule should take the attachment from only apple iPad item not from the rest and add it to a data source)
In future when I request apple iPad catalog item again with an attachment added this should replace the old attachment on the data source and add a new one. and should not insert additionally,
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 04:12 AM
Hi @aravind23 ,
Write a after insert/update BR on sc_req_item table with condition like item = 'apple ipad'
and In the script use the below line.
GlideSysAttachment.copy('sc_req_item', current.sys_id, 'sys_data_source', '8149936d8709111093468517cebb358e'); //8149936d8709111093468517cebb358e - sys_id of the data source
Regards,
Teja
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 05:53 AM
Hi @aravind23 ,
Adding to the above point from Teja11 you can use the below script to delete the existing attachment from the Data Source.
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id','<sys_id of data source');
gr.query();
if(gr.next())
gr.deleteRecord();
Mark Helpful if it helps in Solving your query.
Regards,
Johns
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 07:20 AM
I covered this as part of my blog few years ago. you can have workflow on your catalog item only.
Data load and transform via Catalog Item
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2023 01:15 AM
@Ankur Bawiskar But the data source is not updated with the recent attachment that's been added from the catalog item. Is there a way I can try to acheive this.
Rest everything works good.