Refresh doc to show changes

Hi,
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 ?
LVL 5
RonaldZaalAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Sjef BosmanConnect With a Mentor Groupware ConsultantCommented:
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?
0
 
RonaldZaalAuthor Commented:
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.
0
 
RonaldZaalAuthor Commented:
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 !
0
 
Sjef BosmanGroupware ConsultantCommented:
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...
0
All Courses

From novice to tech pro — start learning today.