How to Hide Attachment icon when the ticket status become "closed"

s_s
Giga Contributor

Hello.

When I closed a ticket, I would like to hide the attachment icon.

find_real_file.png

I referred to https://community.servicenow.com/community id=community_question&sys_id=14fa8dc0db8b5b0423f4a345ca96... and created client script as below.

find_real_file.png

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.

1 ACCEPTED SOLUTION

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

View solution in original post

19 REPLIES 19

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.

Can you share your complete onload client script written for this scenario? I have test on my instance and its working

Thanks,

Sanket

Hi S.S,

Please make change to the Script as below: 

Below Script is test and works fine on my instance.

find_real_file.png

 

 

 Remove below line from onChange client Script :

if (isLoading && newValue==='')
{
return;
}


function onChange(control, oldValue, newValue, isLoading, isTemplate) 
{
	if(newValue == '3')
	{
		g_form.disableAttachments();
	} else 
	{
		g_form.enableAttachments();
	}

}

 

Regards,

Sanket

Thank you for your help.

I think maybe because of cache.

AbhishekGardade
Giga Sage

Recommended option as per docs:

You can prevent users from adding attachments to records on a specific table.

  1. Open a record in the table.
  2. Right-click the form header and select Configure > Dictionary.
  3. In the list of dictionary entries, select the first record in the list (the record with no Column name entry).
  4. Add no_attachment to the Attributes field, separated by commas from any existing attributes.
    See Dictionary attributes for more information.

       

     

you can achieve this by DOM Manipulation but it is not recommended by ServiceNow.

Please mark as Correct Answer and Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies

Thank you,
Abhishek Gardade