delete any existing attachments for a data source via workflow run script

RudhraKAM
Tera Guru

can some one help me with the script where it need to check if there is any attachment to the defined data source , if yes delete that attachment

1 ACCEPTED SOLUTION

Krupamayee
Kilo Expert

Hi the below should work in Run script activity of the workflow:

var gr = new GlideRecord('sys_data_source.');
gr.addQuery('sys_id', 'Sys id of the data source');
gr.query();
if (gr.next()) {
var attach = new GlideSysAttachment();
attach.deleteAll(gr);
}

 

Please mark the answer correct/helpful if it resolved your issue.

-Krupa

View solution in original post

3 REPLIES 3

Krupamayee
Kilo Expert

Hi the below should work in Run script activity of the workflow:

var gr = new GlideRecord('sys_data_source.');
gr.addQuery('sys_id', 'Sys id of the data source');
gr.query();
if (gr.next()) {
var attach = new GlideSysAttachment();
attach.deleteAll(gr);
}

 

Please mark the answer correct/helpful if it resolved your issue.

-Krupa

Hi RudraKAM,

May I know if the answer suggested was correct and helpful?

If yes, please mark the same or let me know in case of any additional questions.

 

-Krupa.

Akshay14
Tera Guru

Hi,

 

I am not sure if I have understood your requirement correctly but below is the API available in ServiceNow to delete any attachments. 

 
 
var attachment = new GlideSysAttachment();
var attachmentSysID = 'a87769531b0820501363ff37dc4bcba2'; //Attachment's sys_id.
attachment.deleteAttachment(attachmentSysID);


Reference link - 
https://developer.servicenow.com/dev.do#!/reference/api/rome/server/no-namespace/c_GlideSysAttachmentScopedAPI#r_SGSA-deleteAttachment_S?navFilter=attachment