using client script

keerthana
Tera Contributor

when incident is resolved attachment need to delete. disable attachment onload. 

5 REPLIES 5

Ravi Chandra_K
Kilo Patron
Kilo Patron

Hello @keerthana 

Greetings!

I think it's not best practice to delete the existing attachments. For future reference, its better to keep the  attachments 

refer the below thread to disable attachment.

https://www.servicenow.com/community/developer-forum/to-restrict-attachment-on-incident-from-once-st...

 

please mark the answer as correct and helpful if helped!

Kind Regards,

Ravi Chandra.

Harish Bainsla
Kilo Patron
Kilo Patron

Create BR


(function executeRule(current, previous /*null when async*/) {
if (current.state === 6 /* Resolved */) {
var attachments = new GlideSysAttachment().getAttachments(current.getTableName(), current.sys_id);
for (var i = 0; i < attachments.size(); i++) {
var attachment = attachments.get(i);
new GlideSysAttachment().deleteAttachment(attachment.getValue("sys_id"));
}
}
})(current, previous);

 

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

Can you explain the why of your requirement? Never heart of such a requirement, sounds strange to do this for all incidents, though maybe you have a solid case for this. Do share so we understand your situation better and can help you correctly instead of just sharing a piece of code.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Samaksh Wani
Giga Sage
Giga Sage

Hello @keerthana 

 

Write this onLoad() Client Script :-

 

 

function onLoad(){

var state = g_form.getValue('state');
if(state == 'resolved'){
g_form.setReadOnly('u_attachment', true);
}

}

 

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh