- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-11-2019 01:17 PM
I am using the below code in Post Script of Scheduled Data Import so as to delete attachment from Data Source.But it is not deleting the attachment.If I try this code from "background script" ,it is working fine.
var dataSourceID = 'xxxxxxxx'; // data source sys id
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_name', 'sys_data_source');
gr.addQuery('table_sys_id', dataSourceID);
gr.query();
if(gr.hasNext())
gr.deleteRecord();
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-11-2019 09:32 PM
Hi Amala,
I remember similar question has been posted on community earlier and has been answered
try to update code as below and check;
also in which scope you are running this scheduled import i.e. global or custom scope
if you are in custom scope app then it blocks deleting attachment from the other scope; i.e. so you need to enable can delete checkbox for sys_attachment table under application access when you open the table
var dataSourceID = 'xxxxxxxx'; // data source sys id
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_name', 'sys_data_source');
gr.addQuery('table_sys_id', dataSourceID);
gr.query();
if(gr.next()){
gs.info('Can Delete Attachment :' + gr.canDelete());
gr.deleteRecord();
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-17-2019 08:07 AM
Hi Amala,
Any update on this?
Can you mark my answer as correct, helpful if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-08-2020 01:46 AM
Hi Ankur
I tried this, but I got an error as below. I did enable 'Can delete' on sys_attachment table. Can you help here
"Error Message
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-08-2020 08:32 AM
Hi Tena,
I would encourage to create new thread for this question as this question is already answered.
It is related to cross scope privilege access
Post the link here and it can be checked
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader