Unable to copy attachment from RITM variable to RITM itself
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2024 02:40 PM
Hi Community,
I have created a attachment variable for catalog item. When I submit the request by attaching a file to variable it is getting stored in sys_attachment table with table name as ZZ_YYsc_cart_item and table sys_id as catalog item sys_id.
I want to copy this same attachment from variable to RITM record itself and as well as to a email notification. But i am unable to Query my RITM record from sys_attachment table and copy the attachment.
Any suggestions would really help me!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2024 01:08 AM
Hi @Haritej
I can understand this pain as once I was a developer I faced the same issue.
You can use the sys_id of the catalog item to query the RITM record. Since the attachment is stored in the sys_attachment table with the table name as ZZ_YYsc_cart_item and the table sys_id as the catalog item sys_id, you can use the following query to get the RITM record:
......................
Let make it super simple assume you have to write a SQL how would you write.. Something like below :-
SELECT *
FROM ritm
WHERE sys_id = <catalog_item_sys_id>
Lets convert it into glide scripting
var ritm = new GlideRecord('ritm');
ritm.get('<catalog_item_sys_id>'); // Replace with the actual sys_id
var attachment = new GlideRecord('sys_attachment');
attachment.get('table_name', 'ZZ_YYsc_cart_item');
attachment.get('table_sys_id', ritm.sys_id);
// Copy the attachment to the RITM record
ritm.attachment = attachment.file;
ritm.update();
follow the video :- https://www.youtube.com/watch?v=4P-AUaNQ8EE