QueryOpen for Document based on doc field?

I’m trying to write a QueryOpen using LotusScript, but the problem is that I want to access a particular field in the document that we’re querying. (Basically, if the user’s name is included in a certain field, then it will allow them in.)

Is this possible? I don’t see how I can get a hold of that field value until I’m in the document. (For example, Set Source = workspace.CurrentDocument won’t work because we’re not yet in the document.)

Subject: RE: QueryOpen for Document based on doc field?

Marc,in the query open, you have access to document using source.

so your code would be like

set doc = source.document

if doc.getItemValue( “userName”)( 0) <> sess.username then

msgbox “no access allowed”

continue = false

exit sub

end if

Subject: RE: QueryOpen for Document based on doc field?

Yes, Source works. Thank you!

But if the field has multiple values, how do I check whether the userName is one of those values? I realize that I’m getting a String array from the getItemValue method, but I don’t know how to check the array. I’ve tried using the Instr method without providing an index on the field, but this fails. I think that I need an “inArray” method rather than “inStr.”

If Instr( doc.getItemValue(“AdditionalEditors”), session.UserName ) > 0 Then 'FAILS HERE

Continue = True

Else

Msgbox “Access to this document is restricted.”

Continue = False

Subject: RE: QueryOpen for Document based on doc field?

Marc,

Stan is right that is what readers and authors are for, however, I have used what you are doing as well. If the arraygetindex give you some issues, you can always use the .contains of the item as well as in…

dim item as notesItem

set item = doc.getFirstItem( “additionalEditors”)

if item.contains( sess.userName) = false then

msbbox “go away Please, you can see this”

continue = false

exit sub

end if

hth John

Subject: RE: QueryOpen for Document based on doc field?

Yes, I was just about to post a question about ArrayGetIndex when I saw Stan’s response. The Readers field is probably what I should use, although I still have some minor issues (see my response to Stan).

So if I do need to fall back on Script, how do I know what Notes version these methods were introduced with? We still have some users on 4.5.6, and I seem to recall an issue with the “contains” method. I would expect this information to be in the Notes Help documentation, but I’m not seeing it.

Subject: RE: QueryOpen for Document based on doc field?

ArrayGetIndex won’t work on R4 either – you would need to use Instr (or an equality check) in a Forall to check all of the values in the array, or Evaluate({@Contains(FieldName;“} + session.UserName + {”)}, doc}).

Subject: RE: QueryOpen for Document based on doc field?

I’ve searched through the forum many times about this similar situation to learn how to restrict user with Editor access from seeing and editing the documents which other user created besides their name was not appeared in any field from the document.

I may coded it wrong but after many failures, I would need Notes guru expert from the forum to help me looking into the code for me below:

  1. I have a form with authors and readers fields, and enter the value for :

Authors field - Computed When Compose - value is “”

Readers Field - Computed when Compose - value is list string of names and field names, I entered into the Reader field all the names as :

@Author:“John Doe”:“Jane Smith”:“Patricia Test”:PCName:PCName2:PCName3:PCName4:PCName5:PCName6:PCName7:PCName8:PCName9

Please advise me how to enter these properly, I guess I didn’t do it correctly here.

  1. If Reader and Author field I would like your guidance again how to enter LS into queryopen event instead of using author and reader fields, which I follow Stan’s instructions from

http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/37de631a07d12aee85257554003aa37e?OpenDocument

Maybe I didn’t entered the name properly from the reader field.

should I use fullname or just CN name?

  1. I really like to use the QueryOpen to control users accessing to the document which they are not author, or their names not in a field from the documents.

Please pardon if this message is not clear, but I will continue to search from the forum.

Best Regards,

Mimi

Subject: RE: QueryOpen for Document based on doc field?

Hello again!

I figured that out by changing the to Computed field value and it works!

Thanks,

Mimi

Subject: RE: QueryOpen for Document based on doc field?

Look at ArrayGetIndex in Designer Help. It’s not exactly Instr, but if you know the exact values you’re looking for, it will help. HOWEVER – this is what Readers and Authors fields are for; there’s no need to code events for this sort of thing.

Subject: RE: QueryOpen for Document based on doc field?

Of course! We’re already using Authors fields, but it never occurred to me to use a Readers field. So this should work in a computed Readers field…

@If(Category != “Assessments”; “”; CreatedBy : Owner : App1 : App2)

That is, if the Category field is not “Assessments,” then no value (and thus no Reader restrictions, right?). Otherwise, contatenate the listed field values for Readers.

BUT one last detail… Is there a way to add roles to this field?

Subject: RE: QueryOpen for Document based on doc field?

Sure is – a role will work as an allowed value in either a Readers or Authors field. Just one thing, though – if your role is for an “always read” value (like the ol’ [Admin] standby), then it’s better to include the role in an Authors field rather than a Readers field. An Authors field will grant read access without removing access from anyone else. (I prefer to keep the “always read” role in its very own Authors-type field so it stays out of the way of any user activity.)

Subject: RE: QueryOpen for Document based on doc field?

But the role(s) would need to be in a separate Readers field, so we would need one for a list of Names, and another for roles, right? For example, it doesn’t seem to like it when I add [Writers] to a list of names.

EDIT: Oh, wait… The roles just need to be in quotes, then they can be concatenated with the other Names. (Right?)

Subject: RE: QueryOpen for Document based on doc field?

They should work together fine and dandy – always have for me.

Subject: RE: QueryOpen for Document based on doc field?

I didn’t have the roles in quotes. Now they seem okay.

(That makes sense, doesn’t it?)

Subject: RE: QueryOpen for Document based on doc field?

Sure do. Hands up all them what’s never fergot…