Make tabs/labels hidden/readonly using API and scripts per item (Part 2)


Now it is possible to protect fields per item. Field protection per item is user independent. Every user can see and edit the same fields on an item. Field protection per item can be used to protect a part of an item when after a script execution one or several tabs/labels or fields need to be protected.
There are two protection levels:

  • Read only
  • Hidden

There are three levels you can protect:

  • Tab
  • Label
  • Field

When protecting a field

  • ReadonlyYN or HiddenYN is set for the field

When protecting a Label

  • ReadonlyYN or HiddenYN is set for the label
  • InheritedReadonlyYN or InheritedHiddenYN is set for the fields starting from the label until the next label or until the next tab

When protecting a Tab

  • ReadonlyYN or HiddenYN is set for the tab
  • InheritedReadonlyYN or InheritedHiddenYN is set for all the labels and fields on the tab until the next tab

When moving a field on the customize page, potentially items can be impacted in the list and in instance lists of a template list. In such a case, user is warned: “Protection of some fields for some items may change. Continue operation?”
When Label is moved, protection of underlying fields (before and after move) is set to the protection level of the Previous Label (or Tab if there is no Previous Label). Label itself gets protection from Tab (inherited properties set, non-inherited stays as it was).
Additional Business rules for protection fields:

  1. User cannot Unprotect Label on Protected Tab
  2.  User can add additional protection level to a Label. (E.g. on ReadOnly Tab user can Hide Label)
  3. Through API User cannot set directly Inherited properties. They will be set automatically set for fields if their Tab or Label changes protection level.
  4. Move item not allowed when there is a protection.

Protection can only be set using API. For these purposes the new entity ItemFieldSetting is introduced.
It has properties: Item, FieldId, IsReadOnly, IsInheritedReadOnly, IsHidden, IsInheritedHidden.
Example of setting standard Status field readOnly for Item with id = 1
var ifs = new ItemFieldSetting() { FieldId = "SF7", Item = new Item { Id = 1 }, IsHidden = true};
Example of retrieving ItemFieldSettings for Item
var item = new Item { Id = 1  };
bool res = API.GetItemFieldSettingsByItem(item);
After that call, collection item.ItemFieldSettings will contain 1 entry with properties equal to properties of the ifs object created in the above example.
ODATA Api: setting standard Status field readOnly for Item with id = 1, user can perform the POST operation with the body:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<entry xml:base="http://localhost/tenforce/Api.svc/" xmlns:d="" xmlns:m="" xmlns="">
  <link rel="" type="application/atom+xml;type=entry" title="Item" href="Items(1)" />
  <category term="TenForce.Execution.Api2.Objects.ItemFieldSetting" scheme="" />
  <content type="application/xml">
      <d:Id m:type="Edm.Int32">0</d:Id>
      <d:IsReadOnly m:type="Edm.Boolean">true</d:IsReadOnly>
      <d:IsHidden m:type="Edm.Boolean">false</d:IsHidden>

How do the GUI and the API correspond?

  • Visibility as shown on the GUI is also applied to the API – fields that are Hidden on the GUI are not retrieved on API calls.
  • ReadOnly attributes only apply to the GUI. Fields of the item can be set through the API, independent of this attribute value.