I have this piece of code which errors with nested events. I am not sure what to do, I have tried many things as I’ve got similar code working, but for some reason this doesn’t want to execute even when the conditions are true.
This is in QuerySave and what I am wanting to do is:
If the document being saved is a New Document and the EmployeeYesNo field is Yes or the Status field is Draft and the EmployeeYesNo field is Yes then…
If ((doc.IsNewNote) And (doc.EmployeeYesNo(0) = “Yes”) Or (doc.Status(0) = “Draft”) And (doc.EmployeeYesNo(0) = “Yes”)) Then
I have another If statement that is the same, but it’s if the EmployeeYesNo field is No then…
I’d really appreciate some help. I don’t think I have the brackets in the right place. I did start this code to be the same as what I’ve already got in another form, but it didn’t work, so I came to have what I’ve posted now…
Subject: RE: If statement in LotusScript not running even if conditions are true?
At this point, it is better to check step by step as follows. First remove your code from QuerySave and copy to a notepad. Save the form. Create a new document and make sure you have no error when you save it.
Then copy only part of code from notepad (like condition by condition) and try to create more documents to test your new save. This way you can know where exactly the problem lies in.
Also use Ben’s clue to simplify your conditional statement.
Subject: RE: If statement in LotusScript not running even if conditions are true?
Yes. This has nothing whatsoever to do with the syntax of your if statements. “Nested form events” errors occur when you try to do something that causes a form even to occur, and you are already executing that form event. For instance, you try to save a document in the front end from code running in the Querysave event of a form. This causes another Querysave to begin before you’re done executing the first one.
Whatever you’re trying to do in your agent, do it with back-end methods (NotesDocument instead of NotesUIDocument), or don’t do it at all. If you say more about what you’re trying to accomplish, odds are there’s a better way.
Subject: RE: If statement in LotusScript not running even if conditions are true?
Hello Andre,
Here is my code in the agent. I’ve taken all the ui stuff out but now email is not being generated and documents are not being created. I’m also not getting any errors though.
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim newdoc As NotesDocument
Dim rtitem1 As NotesRichTextItem
Set db=session.CurrentDatabase
Set doc=New NotesDocument(db)
Set newdoc=New NotesDocument(db)
Set rtitem1 =New NotesRichTextItem(newdoc,"Body")
If (doc.FieldGetText("EmployeeYesNo") = "Yes") Then
newdoc.Form="Memo"
newdoc.Subject="Business Drivers DB - Authorised Driver form needs Facilities Approval for " & doc.FieldGetText( "FullName" )
Call rtitem1.AppendText("This Authorised Drivers form for " & doc.FieldGetText( "FullName") & " has been approved by " & doc.FieldGetText( "AuthorisedName" ))
Call rtitem1.AddNewLine(1)
Call rtitem1.AppendText("Facilities are now required to check all documentation and approve this form.")
Call rtitem1.AddNewLine(2)
Call rtitem1.AppendText("Please follow the link to view the document ->> ")
Call rtitem1.AppendDocLink(doc,db.Title)
Call rtitem1.AddNewLine(2)
Call rtitem1.AppendText("Thank you...")
Call rtitem1.AddNewLine(2)
flag=newdoc.ComputeWithForm(False,False)
Call newdoc.Send (False, doc.FieldGetText( "Facilities" ))
Else
newdoc.Form="Memo"
newdoc.Subject="Business Drivers DB - Authorised Driver form needs Facilities Approval for " & doc.FieldGetText( "SpouseName" )
Call rtitem1.AppendText("This Authorised Drivers form for " & doc.FieldGetText( "SpouseName") & " (Additional Driver) has been submitted by " & doc.FieldGetText( "CreatedBy" ))
Call rtitem1.AddNewLine(1)
Call rtitem1.AppendText("Facilities are now required to check all documentation and approve this form for the additional driver.")
Call rtitem1.AddNewLine(2)
Call rtitem1.AppendText("Please follow the link to view the document ->> ")
Call rtitem1.AppendDocLink(doc,db.Title)
Call rtitem1.AddNewLine(2)
Call rtitem1.AppendText("Thank you...")
Call rtitem1.AddNewLine(2)
flag=newdoc.ComputeWithForm(False,False)
Call newdoc.Send (False, doc.FieldGetText( "Facilities" ))
End If
Subject: If statement in LotusScript not running even if conditions are true?
Thank you James, that’s kind of working as in the correct If statements are running, but when the conditions of the EmployeeYesNo field are No, it errors with Nested events… The code when it’s Yes, is working without any errors. Any ideas, here is the other bit of code:
If ((doc.IsNewNote And doc.EmployeeYesNo(0) = “No”) Or (doc.Status(0) = “Draft” And doc.EmployeeYesNo(0) = “No”)) Then
and here it is which is now working:
If ((doc.IsNewNote And doc.EmployeeYesNo(0) = “Yes”) Or (doc.Status(0) = “Draft” And doc.EmployeeYesNo(0) = “Yes”)) Then
I’m not sure if it has anything to do with it, but when the EmployeeYesNo field is “No”, then it runs some agents, heres the complete code for you:
If ((doc.IsNewNote And doc.EmployeeYesNo(0) = "No") Or (doc.Status(0) = "Draft" And doc.EmployeeYesNo(0) = "No")) Then
Dim agent As NotesAgent
Set agent = db.GetAgent("ADF_TMVMForm")
Call agent.Run
Dim agent1 As NotesAgent
Set agent1= db.GetAgent("ADF_FacilitiesApproval")
Call agent1.Run
Dim agent2 As NotesAgent
Set agent2 = db.GetAgent("ADF_TrainingLog")
Call agent2.Run
Call source.FieldSetText("AppToggle", "No")
Call source.FieldSetText("AuthToggle", "Yes")
Call source.FieldSetText("SusToggle", "Yes")
Call source.FieldSetText("Status", "Approved")
Exit Sub
End If
I appreciate your help. I have run this through debug and stuff, so I know the values are correct.