In this agent, ws.CurrentView is Nothing even though a view is open. Then, it tries to re-open the database that the client already has open, and the client crashes. (NSD)
Here is our scenario:
The user is in Notes Client in any view of “Sheep” docs and opens any one of them. It opens in Read mode.
The user clicks a shared action, “Clone”.
The code for “Clone” goes to edit mode, saves, goes back to read mode, and runs a LotusScript agent:
@Command([EditDocument]; “1”);
FIELD SaveOptions := @DeleteField;
@If(@Command([FileSave]); 0; @Return(0));
FIELD SaveOptions := “0”;
@Command([EditDocument]; “0”);
@Command([RunAgent]; “SheepClone”)
The debugger shows that the UI events execute in an different order than I expected. But with @Commands I guess that is not surprising. It ends with two consecutive PostModeChange()s, then starts the Initialize() of the agent.
The “SheepClone” agent creates and saves a new Sheep doc to represent the Cloned sheep. Then it should open the new Sheep in the UI.
If I stop the debugger before the code to open it, “Sub OpenClone()”, everything is fine. But the following code leads to a crash and an NSD (or, in the debugger, it often hangs):
Public Sub OpenClone (docToOpen As NotesDocument)
'/**
' * Open the "NotesView" frame in Sheep Shearer to a view containing that a specified document,
' * and place the cursor on that document.
' */
Dim uidb As NotesUIDatabase
Dim uiview As NotesUIView
Dim view As NotesView, vwUI As NotesView
Dim sPageOld As String, sPageNew As String
Set db = docToOpen.ParentDatabase
’ ws is a global in another script library, it was set in the Initialize() of that lib
Set uidb = ws.GetCurrentDatabase
If uidb Is Nothing Then
' do nothing
Elseif uidb.Database.Server <> db.Server Or uidb.Database.FilePath <> db.FilePath Then
Set uidb = Nothing
Elseif ws.CurrentView Is Nothing Then
Set uidb = Nothing
End If
If uidb Is Nothing Then
ws.OpenDatabase db.Server, db.FilePath
............................
In the debugger, it switches windows to the client, and hangs, at this point. Without the debugger, the client crashes and NSDs, I presume it happens at this line. Or the client redisplays but NSD’s at the next action.
(My first question is answered already by another thread - wish I had found it in my first 10 tries - that one is
Question 1 - The debugger shows that, from the start of agent execution, “ws.CurrentView” is Nothing. Is that the behavior one expects? >>>YES IT IS WAD - DOCUMENT WAS CURRENT NOT VIEW.<<< A view was open in the UI after all. ws.GetCurrentDatabase() works as expected in the above code.
Question 2 - The problem seems to occur at the line when the code tries to open the DB that is already open, with
ws.OpenDatabase()
Can you do that?