- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 03:47 AM
Hello Everyone,
I want to delete the attachments that are linked to specific item from Request Item.
I'm trying to write a fix script but it is not working.
var inuser = new GlideRecord('sc_req_item');
inuser.addQuery('cat_item', '62f4956bdbc4285455e326c2ca96191a');// Item Sys ID
inuser.query();
while (inuser.next()) {
var attach = new GlideRecord('sys_attachment');
attach.addQuery('file_name', inuser.sys_id);
attach.query();
while (attach.next()) {
attach.deleteRecord();
}
}
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 03:54 AM - edited 12-05-2023 03:54 AM
Hi @Rakesh40 ,
Plz try the below code. with rollback option enabled as we are trying to delete record. I have added two logs plz run the script as it is n check the logs if u r satisfied then remove the comment from delete record command & execute it.
var inuser = new GlideRecord('sc_req_item');
inuser.addQuery('cat_item', '62f4956bdbc4285455e326c2ca96191a');// Item Sys ID
inuser.query();
while (inuser.next()) {
var attach = new GlideRecord('sys_attachment');
attach.addQuery('table_sys_id', inuser.sys_id);
attach.addQuery('table_name','sc_req_item');
attach.query();
while (attach.next()) {
gs.info('Sys ID of attachment'+ attach.sys_id);
gs.info('FileName of attachment'+ attach.file_name);
//attach.deleteRecord();
}
}
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 03:54 AM
Hello @Rakesh40
Modify your script with mine :-
attach.addQuery("table_sys_id", inuser.sys_id);
Plz mark my solution as Accept, If you find it helpful.
Regards,
Samaksh Wani (Rising Star 2023)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 04:31 AM
Hi @Rakesh40 ,
If our responses helped you could you please mark it as Solution Accepted so that other users could benefit from it.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 04:40 AM
Hello @Rakesh40
If my response helped in solving your query, Please mark it as Accepted. It will other community users.
Regards,
Samaksh