Hide ‘Delete’ button from ‘Attachments’ section in NITRO Forms based on user permissions

Applies To

Crow Canyon NITRO activated sites in:
SharePoint Online and On-Premises 2013/2016/2019

Description

Users who can edit the items can also delete item attachments. Sometimes it is required that users should be able to edit items but should not be able to remove attachments. This article has the steps to hide ‘Delete’ button from ‘Attachments’ section in NITRO Forms based on logged in user group membership.

Detailed Steps

  1. Identify the SharePoint groups that will have permissions to delete attachments. For all other users delete button will be hidden.
  2. Navigate to NITRO Forms of the list. Expand ‘Advanced’ section (in the left-hand panel) -> add CSS in ‘Custom CSS’ as shown below:

Script:

.SPUserNotInGroup div#divAttachments table td:last-child {
display: none;
}
  1. Add below script in ‘Custom JavaScript’ section.

Note: Please replace “group 1” and “group2” names highlighted in below script with required SharePoint groups. Users who are members of any of the specified groups will be able to see the “Delete” button in NITRO Forms. For all other users, it will be hidden.

Script:

var userInGroup = false;
var deleteAllowedGroups = ["group1", "group2"]; // specify group names in lowercase
if (formContext.conditionEvalUtility.CurrentUser.Groups && formContext.conditionEvalUtility.CurrentUser.Groups.length > 0) {
for (var i = 0; i < formContext.conditionEvalUtility.CurrentUser.Groups.length; i++) {
if (deleteAllowedGroups.indexOf(formContext.conditionEvalUtility.CurrentUser.Groups[i].toLowerCase()) > -1) {
userInGroup = true;
break;
}
}
}

if (!userInGroup) {
$("body").addClass("SPUserNotInGroup");
}

Sample Output