- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2019 10:40 PM
Hello.
When I closed a ticket, I would like to hide the attachment icon.
I referred to https://community.servicenow.com/community id=community_question&sys_id=14fa8dc0db8b5b0423f4a345ca96... and created client script as below.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var checkValue = g_form.getDisplayBox('state').value;
if (checkValue == "Closed"){
g_form.disableAttachments();
} else {
g_form.enableAttachments();
}
}
However, It doesn't work.
I would appreciate it if you could answer.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2019 10:57 PM
Hi
Sorry for the script above, please try with this -
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
//var checkValue = g_form.getValue('state').value;
if (newValue == 7)//check for Closed state backend value{
g_form.disableAttachments();
} else {
g_form.enableAttachments();
}
}
Regards
Omkar Mone

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2019 10:46 PM
Hi
The below code would hide the attachment icon ( DOM manipulation is required), it wont work on portal, also remember to untick the isolate script checkbox on the client script that prevents the dom manipulations.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var checkValue = g_form.getDisplayBox('state').value;
if (checkValue == "Closed"){
var attachmentButton = top.document.getElementsByTagName('sp-attachment-button');
attachmentButton[0].parentNode.hidden = true;
//g_form.disableAttachments();
} else {
//g_form.enableAttachments();
}
}
Hope this helps.
Regards
Omkar Mone

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2019 10:57 PM
Hi
Sorry for the script above, please try with this -
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
//var checkValue = g_form.getValue('state').value;
if (newValue == 7)//check for Closed state backend value{
g_form.disableAttachments();
} else {
g_form.enableAttachments();
}
}
Regards
Omkar Mone
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2019 11:42 PM
Thank you for your reply.
Sorry for the lack of explanation.
I would like to apply the client script to case tickets.
Therefore, the value should be 3,but even if I changed this value to 3, the attachment icon didn't hide.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2019 10:49 PM
Hi,
Please try with below solution:
write script on onload client script
function onLoad() {
//Type appropriate comment here, and begin script below
var checkValue = g_form.getDisplayBox('state').value;
if (checkValue == '7') //7 is value of Close state
{
g_form.disableAttachments();
} else {
g_form.enableAttachments();
}
}
Regards,
Sanket