using client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 09:27 PM
when incident is resolved attachment need to delete. disable attachment onload.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 09:31 PM
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.
please mark the answer as correct and helpful if helped!
Kind Regards,
Ravi Chandra.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 09:35 PM
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 as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 09:43 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 10:59 PM
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