checkAccess

[ Function ]

public static checkAccess(
   control: TcHmi.Controls.System.baseTcHmiControl,
   requestedAccessright: string
): boolean | null;

Checks an access right of a control. All controls provide the operate and observe rights. Controls can define additional rights names and respond accordingly. Rights are always assigned to groups.

If a right is not explicitly defined on a control itself, its parent control is checked. Therefore, a check is only possible after attaching.

Possible situations:

Parameter

Name

Type

Description

control

TcHmi.Controls.System.baseTcHmiControl

Control to be checked

requestedAccessright

string

Name of the access right to be checked

Return value

Type

Description

boolean, null

true: The control currently has this right.

false: The control does not currently have this right.

null: The access right cannot currently be decided. See above.

checkAccess 1:

Available from 1.8

Sample - JavaScript

A right is to be checked in a separate event handler. This must be added in Description.json, otherwise the right cannot be configured in Visual Studio.

var myDiv = $('<div>Hello World!</div>');
myDiv.on('click', function(evt) {
   if(TcHmi.Access.checkAccess(myControl, 'doFancyStuff') !== true){
      return; // current user has no right to do this
   }
   // fancy stuff
});
myControl.getElement().append(myDiv);