We help IT Professionals succeed at work.

Refresh doc to show changes

RonaldZaal asked
Notes client form : On button click:
1) runs an agent to change some doc values and add authors
2) refresh the doc and show new values and go into edit mode.

Sub Click(Source As Button)
      Dim ws As New NotesUIWorkspace
      Dim session As New NotesSession
      vAnswer = Messagebox (("Wanna update?"), 4 , "Update")
      If vAnswer = 6 Then
      'get updated
            Call UpdateFactPattern(doc, uidoc)      ' calls an agent which sets author values and statusfield
            docUnid = doc.noteID
            Call uidoc.Close
            Set db = session.CurrentDatabase
            Set doc = db.GetDocumentByid(docUnid )
            Set uidoc = ws.EditDocument(True, doc)
            Call uidoc.Refresh
            Call uidoc.GOTOFIELD("Subject")
      End If      
End Sub
When I Esc out of the uidocument and refresh the view I see that the doc has all the correct values.
How can I open the doc for the user in edit mode with directly the correct values which I setted with  the agent ?
Watch Question

Groupware Consultant
1) Why call an agent, and not the function? Save the function in a Script library, and use the same function from the agent and from the code above, in a form.
2) I assume your code works. If so, then all you need is a ws.ViewRefresh
3) If the code doesn't work, try to move the uidoc.Close to much later in your code. Of course you would need to declare a new object for the new form, but who cares. The Close might kick in before your code can finish.

If this doesn't do the trick, where did I not understand you?


Hoi Sjef,
1) I call an agent to reset the Author rights on the doc.
    At first the user doesn't have Author rights, only read rights.
    I'm running an agent to give Author rights to the user which clicks the button.

So the Button calls the script lib. , which calls the agent to set the rights and new status
Lib code :
Sub UpdateFactPattern(docCurrent As notesdocument, uidoc As NotesUIDocument)
      Dim agSync As notesagent
      Dim docError As notesdocument
      Dim agResult As Variant
      Dim dbCurrent As NotesDatabase
      Set dbcurrent = docCurrent.ParentDatabase
      Set agSync = dbCurrent.GetAgent("agUpdateFacts")
      On Error Resume Next
      agResult = agSync.RunOnServer(docCurrent.NoteID)
End Sub

Agent Code :
Sub Initialize
      Dim dbCurrent As NotesDatabase
      Dim sesCurrent As New NotesSession
      Dim docAnswer As Notesdocument
      Dim dbQuestion As NotesDatabase
      Dim docQuestion As Notesdocument
      Dim docQuestionProfile As notesdocument
      Dim vwQuestionProfile As NotesView
      Dim namBehandelaar As NotesName
      Set dbCurrent = sesCurrent.CurrentDatabase
      Dim agCurrent As notesagent
      Set agCurrent = sesCurrent.CurrentAgent
      Set docAnswer = dbCurrent.GetDocumentByID(agCurrent.ParameterDocID)
      docAnswer.Status = "Consultation in progress"    ' New Status
      docAnswer.StatusNr = "3"   ' New Status NR
      docAnswer.AnswerDB = "" 
            ' fill eng leader and eng manager
      Dim namLeader As NotesName
      Dim namManager As NotesName
      Set namManager = New NotesName(docAnswer.Engmanager(0))
      Set namLeader = New NotesName(docanswer.RespPartner(0))
      Dim itmReaders As notesitem
      Dim itmAuthors As NotesItem
      'Set the readersfield with multiple values      
      Set itmReaders = docAnswer.ReplaceItemValue( "ReadersDoc", docAnswer.Naam(0))      
      Call itmReaders.AppendToTextList(namManager.Canonical)  
      Call itmReaders.AppendToTextList(namLeader.Canonical)  
      'Set the authorsfield with multiple values      
      Set itmAuthors = docAnswer.ReplaceItemValue( "AuthorsDoc", docAnswer.Naam(0))
      Call itmAuthors.AppendToTextList(namManager.Canonical)  
      Call itmAuthors.AppendToTextList(namLeader.Canonical)  
      Call docAnswer.Save(True,False)      
End Sub

2) I tried to add ws.viewrefresh at multiple places to get things refreshed but no result
    Maybe I didn't put in the right place.


The problem was in the agent.......   a collegue found it in 5 min time....  
i promise i will never use " on error resume next "   again  :-)
Hey Sjef, thanks for the support anyway !
Sjef BosmanGroupware Consultant

That solves all problems indeed, "On Error Resume Next" :-))

Why agent: okay, I understand. Be careful with Authors and Readers fields, I've seen it happen that they lose their special setting, so I always add a line with
    itmAuthors.IsAuthors= True
and similar for a Readers field.

Anyway, thanks for the points. You'd better tell your colleague to get an EE account...

Explore More ContentExplore courses, solutions, and other research materials related to this topic.