How to make the attachment read only and cannot be deleted for SC_TASK table

Rohit Reddy
Tera Contributor

How to make the attachment read only and cannot be deleted for SC_TASK table.

 

We have a requirement that user should be able to attach any attachment on the record in sc_task table, but cannot delete it.

2 REPLIES 2

Riya Verma
Kilo Sage
Kilo Sage

Hi @Rohit Reddy ,

Hope you are doing great.

 

To fulfill the requirement of making attachments read-only and preventing their deletion for the "sc_task" table in ServiceNow, you can follow the steps outlined below:

  1. Navigate to the "sc_task" table in the ServiceNow instance.

  2. Access the table's dictionary by clicking on "System Definition" > "Tables & Columns" > "Dictionary".

  3. Search for the field that represents the attachment functionality on the "sc_task" table. The default field name for attachments is usually "u_attachment".

  4. Once you locate the field, click on its name to access the field's dictionary entry.

  5. In the field's dictionary entry, you will find various properties and settings. Look for the "Read Only" property and set it to "true". 

  6. you can modify the related UI policy to hide the delete button specifically for the attachment field, further ensuring that users cannot delete attachments. 

  7. Edit the UI policy and add a condition targeting the attachment field (e.g., "u_attachment") to hide the delete button. This can be achieved by setting the condition's script to something like:

 

current.variables.u_attachment.canDelete = false;

 

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

Arun_S1
Tera Guru
Tera Guru

@Rohit Reddy The control to add/remove attachments are controlled by the UI Page "attachment". Please make the below changes in the UI Page

 

I have replaced the line"<j:set var="jvar_can_edit_attachments" value="true" />" in line number 96 & 91 this is modified to the below code to check if the table is sc_task and hide the remove button.

 

<j:if test="${jvar_target_table != 'sc_task'}" >
	<j:set var="jvar_can_edit_attachments" value="true" />
</j:if>

 

 

After making these changes, I am not able to see the remove option for sc_task

 

Arun_S1_0-1688566566602.png

 

and the same works for incident

Arun_S1_1-1688566602231.png

Please mark the appropriate response as correct answer and helpful