Personal tools
You are here: Home / How to / Restrict access to documents

Restrict access to documents

How to allow or not to open a document depending on the current user.

Let's assume your form contains a Name field and you want to restrict access to documents according this field value.

This field would be named "employee" for instance

Note: if you want it to store the id of the user who creates the document just make it Computed on creation, with the following formula:

plominoDocument.getCurrentUser().getMemberId()

To restrict access to the document, we will use the onOpenDocument event: if this event formula returns anything false (False, None, 0, ""), the document opening is allowed, but if it returns a non-empty string, the opening is not allowed and the returned string is display to the user as error message.

So edit your form, and go to Events tab, and enter a formula like this in the On open document event:

if plominoDocument.getCurrentUser().getMemberId()==plominoDocument.employee:
return None
else:
return "You are not allowed to view this document." 

If you also want to allow users having a given role (let's say [controller]), you would use a formula like this:

if plominoDocument.getCurrentUser().getMemberId()==plominoDocument.employee:
  return None
roles=plominoDocument.getCurrentUserRoles()
if "[controller]" in roles:
return None
return "You are not allowed to view this document." 
Document Actions