$object.canWriteAttribute($attribute)
canWriteAttribute($object, $attribute)
Checks whether the currently logged-in user is allowed to modify the given attribute of the given object and returns a boolean.
This is the attribute-level counterpart of canWrite and the natural guard before a set: instead of running into the permission error that set raises for a non-writable attribute, a script can check first and branch. The function never fails and never filters.
The check is evaluated for the currently logged-in user and follows the same rules as the implicit permission enforcement: deny-by-default, role inheritance along the security hierarchy, and full access for administrators or executions in a system context.
| Name | Type | Type Description | Mandatory | Default |
|---|---|---|---|---|
| object | Business object | The object to check. | yes | |
| attribute | Attribute | The attribute (TLStructuredTypePart) whose write access is checked. | yes |
Type: Boolean
true if the current user may modify the attribute on the object, false otherwise.
if($contract.canWriteAttribute(`my.module:Contract#status`), $contract.set(`my.module:Contract#status`, "done"), null)
Output: Sets the status only if the logged-in user may write that attribute – otherwise nothing happens, without a permission error.