Refresh/Update on QueryOpen IF user = names field

110 pts.
Lotus development
The documents have complicated security, so I need to check if the user matches either of a few names fields first. If yes I need the documents updated (same as if user clicked and Edit button and saved and refreshed) so that certain fields that are pulling values from a view that draws from a different form, can updated. I need to happen when the user opens the document. R5.0.13 I've tried source.FieldGetText Set Nitem = source.GetFirstItem to get the values to compare then Source.Editmode = True Call Source.Editmode = False

Answer Wiki

Thanks. We'll let you know when a new response is added.

This is a tricky area, the first thing to remember is that you need to compare like with like so convert the current users name into a notesName and read each name from the security fields into notesNames for comparison purposes.

You get the current user from notesSession

dim s as new notesSession
set currentUserName = new notesName(notesSession.EffectiveUserName)

Each name you are comparing can be extracted from field item values
set editorNames = doc.editorNames
forall value in editorNames.values
if value <> “” then
Set editorName = new notesName(value)
End If
end forall

This might not be realistic if you have too many names too compare against, you might need to review the whole security model as it might no longer be appropriate for the current application.

Discuss This Question: 4  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Joeydog
    Thanks, I can get the user name ok, but I am having trouble extracting the names fields from the document. What methods work best in Postopen? There are 3, say okName1, okNmae2, okName3. Can you help with this? I tried : Dim okNameA as As notesName Set okNameA = New notesName(notesSession.okName1) Set user = New notesName(notesSession.CommonUserName) If user = okNameA Then Source.Editmode = True Call Source.Editmode = False End If but I am getting a Type mismatch error. R5.01.13
    110 pointsBadges:
  • Brooklynegg
    You have no reference to the document that has the field values. Here's some code I put together from help information and combined with your examples. I have not tested this at all, but it should be close, assuming your user value gets set correctly. These methods should be correct for PostOpen. In your example, I don't understand why you would save the document as soon as you force it into edit mode. I am against forcing saves. If the user makes changes and wants to save them, they can. You should give them the ability to discard changes. Dim session As NotesSession Dim db As NotesDatabase Dim dc As NotesDocumentCollection Dim doc As NotesDocument Dim editorname As Variant Set session = New NotesSession Set db = session.CurrentDatabase Set dc = db.UnprocessedDocuments Set doc = dc.GetFirstDocument do until doc is nothing Set user = New notesName(notesSession.CommonUserName) editorname = doc.okName1 if user = editorname(0) then 'the rest of your code end if set doc = dc.getnextdocument(doc) loop
    3,845 pointsBadges:
  • Joeydog
    Sorry if I haven't made my issue clear. I don't need to loop through all the documents. If the user's commonname opening the document matches either okName1, okName2, okName3 names of that document being opened, then I need that document to refresh the values in the computed fields ( RouteTo1, RouteTo2) of that document. So, when the user looks at their document it shows the correct values in RouteTo1, RouteTo2. Currently I rely on the user, opening their document to put it in Edit Mode, click Save then F9 to refresh before they route it (a button Action). But they don't always do this and the document is being routed incorrectly. As I tried to explain in my first post the computed fields that needs to be refreshed when opened, get their values from a view that draws from a different form (Maintain Names for Routing) that could be changed any time from a different user, but within the same db. There is no choice for the user to make, the computed fields need to refresh so that the document can route properly. PostOpen will run before the user puts any of their own changes in. Then normal Save conditions will apply for them. I basically just need the document to refresh when opened, but only if the current user is one of those 3 okName fields. The biggest problem is understanding what PostOpen can do because if I use Call source.Save or Call source.Refresh I get a Document Command not available message. If I put it in Editmode then save, it refreshes ok, but I need it back in Read mode which causes it to loop. This code loops: Sub Postopen(Source As Notesuidocument) Dim db As NotesDatabase Dim workspace As New NotesUIWorkspace Dim uidoc As NotesUIDocument Dim doc As NotesDocument Dim NitemokName1 As NotesItem Dim NitemokName2 As NotesItem Dim NitemokName3As NotesItem Dim session As New NotesSession ' Dim update As String <== is Global declared Initialized with a "" value Set wksp = New NotesUIWorkspace Set session = New NotesSession Set db = session.CurrentDatabase Set uidoc = workspace.CurrentDocument Set doc = uidoc.Document Set NitemokName1 = doc.GetFirstItem("okName1") Set NitemokName2 = doc.GetFirstItem("okName2") Set NitemokName3 = doc.GetFirstItem("okName3") If update <> " Change Done" And (NitemokName1.contains(session.commonusername) = True) _ Or (NitemokName2.contains(session.commonusername) = True) _ Or (NitemokName3.contains(session.commonusername) = True) Then Source.Editmode = True Call uidoc.Save update = " Change Done" Source.Editmode = False End If End Sub **Querymodechange checks a Status field, if Closed no edit allowed. This is driving me crazy, I didn't thnk this would take so long to resolve. Thanks for any help!
    110 pointsBadges:
  • Joeydog
    Hi Again Just to clarify, I am now getting my user commonname to compare to these field values ok: okName1, okName2, okName3. It is the "how to refresh" without causing a loop now! If I leave out the Source.Editmode = False line, all my data is correct, but want it back to Read mode. Thanks
    110 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: