How to determinate if user can edit document in LotusScript?

How to determinate if user can edit document in LotusScript? I found this way which is not the best:

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Set uidoc=ws.CurrentDocument

uidoc.EditMode=True

If(uidoc.EditMode=False) Then

'not allowed to edit

Else

'allowed to edit

End If

Subject: RE: How to determinate if user can edit document in LotusScript?

Are you saying that the way you show doesn’t work, or is it that you want a way that doesn’t require you to put the document into edit mode?

You could duplicate the rules by which Notes makes this determination, but it’s a little complex. It’s based on whether the user has Editor access or higher, on whether the document contains Authors fields and whether those fields have any values in common with the values in @UserNamesList, on whether there’s a $PublicAccess field. I don’t have the whole thing already written up as an algorithm.

However, if you can arrange the database accesses and roles so that all the people with access to edit the document are members of one or more roles, then you can easily test whether @UserRoles contains one of those roles.

Subject: RE: How to determinate if user can edit document in LotusScript?

Actually, this is a major annoyance in Notes interface design, Andre. Because there’s no obvious method to determine “can the user edit THIS document,” we can’t do things like use a hide-when on an action button that might go into Edit mode. Even with the check of Editor access or membership in an Authors list, you hit one level of cascading, and it’s next to impossible to do.

It really would be nice to have something like @UserCanEdit.

Subject: Re: How to determinate if user can edit document in LotusScript?

I agree - this would be a nice feature to have, both in @Formulas and LS.

As it stands now you can hack your way around it with a computed-for-display field with @UserNamesList, and check that against your known Readers and Authors fields’ elements, but it’s not extremely elegant. It gets especially nasty if you’ve got multiple Readers/Authors fields to worry about, or cases where there is none at all.

Subject: RE: Re: How to determinate if user can edit document in LotusScript?

You don’t really have to check Readers fields, because if the user doesn’t have access to read the document, they will never see it for you to apply formulas to it.

A good general-purpose formula is the following:

@If(@UserAccess > 3; @True; @UserAccess < 2; @False; @UserNamesList *= @Author)

It doesn’t deal with the case of public-access documents, but I think it’ll do for most of the cases where you need such a formula. It’s a little more reliable to use the actual authors fieldnames ( (field1 : field2) ) instead of @Author, since the From field is not necessarily an authors field. Of course, if the document is already in edit mode the user has access to edit, but you can use a checkbox to hide in that case and not have to evaluate the formula.

Subject: Perfect, thanks

As always, your posts are very helpful.

Just a note to newer developers, a more “ready to use” formula would be:

ua := @TextToNumber(@UserAccess(@DbName));

@If(ua > 3; @True; ua < 2; @False; @UserNamesList *= (@Author : authors))

(in my case where authors is the one and only authors field on my form)

Subject: RE: Re: How to determinate if user can edit document in LotusScript?

Handy formula, Andre, and a bit more elegant that I probably would have written it, so thanks.

Given that this is about 90% likely to be used as an action bar hide-when, let’s hope it’s not too expensive.

I still think a very obvious @function would be nice for novices, though. Maybe then, the internal template designers could use to it to hide things like Actions - Edit Document in the log, when the user only has reader access. :wink:

(Did I just call them novices? grin)

Subject: RE: How to determinate if user can edit document in LotusScript?

It works but show document on screen and user can see how document becomes editable and then in read mode again. I will like not to have this visual “effects”.