Syntax

$object.canWriteAttribute($attribute)

canWriteAttribute($object, $attribute)

Description

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.

Parameters

NameTypeType DescriptionMandatoryDefault
objectBusiness objectThe object to check.yes
attributeAttributeThe attribute (TLStructuredTypePart) whose write access is checked.yes

Return value

Type: Boolean

true if the current user may modify the attribute on the object, false otherwise.

Examples

Example 1

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.