I have the following script in a PostOpen event which is giving me the error “Variant does not contain an object”. Can anyone tell me where I’m going wrong?
Thanks,
Sub Postsave(Source As Notesuidocument)
Dim uidoc As NotesUIDocument
Set uidoc=ws.CurrentDocument
If docCurrent.pctComplete(0)="100" Then
Call docCurrent.FieldSetText _
( "reqStatus", "Complete" )
End If
End Sub
Subject: you have not set doccurrent
Subject: Variant does not contain an object
Sub Postsave(Source As Notesuidocument)Dim docCurrent as NotesDocument
set docCurrent=source.Document
If docCurrent.pctComplete(0)=“100” Then
docCurrent.reqStatus=Complete
End If
'and you also did not save the document
Call docCurrent.Save (true, false)
End Sub
Angie, when you run the debugger it will take you to exactly where the error is occuring and there you can see the variables to see what is missing.
remember that the postsave event is independent of the QuerySave event, where it might be better to include the change anyways…
Subject: Is there a better way to append a doclink?
I’ve got the following code in my database which my intention is to send the content of Body1 in the body section of the memo. I’d also like to append a doclink but what I’m doing is overwriting the text with the link.
Any help is greatly appreciated!
Sub Querysave(Source As Notesuidocument, Continue As Variant)
'Get a handle on the Notes Session
Dim session As New NotesSession
'Get a handle on the Current NotesUIWorkspace
Dim ws As New NotesUIWorkspace
'Get a handle on the uidoc and underlying document
Dim uidoc As NotesUIDocument
Set uidoc=ws.CurrentDocument
'Get a handle on the current database
Dim db As NotesDatabase
Set db = session.CurrentDatabase
'Assign variables
Dim IssueNum As String
Dim SendTo_1 As Variant
Dim docCurrent As NotesDocument
Set docCurrent = uidoc.Document
Dim tmp As String
Dim Assignees As String
Dim agent As NotesAgent
Dim rtitem As NotesRichTextItem
Set agent = db.GetAgent("Set Sequential Number")
Call agent.run
If docCurrent.Assignees(0) <> docCurrent.tmpAssignees(0) Then
'Present the dialogbox
docCurrent.Form = "Memo"
Call ws.DialogBox( "dlgTest", True, True, True, False, False, False, "Message Content Only")
End If
docCurrent.tmpAssignees=""
docCurrent.SendTo = docCurrent.Assignees
docCurrent.Subject = docCurrent.Subject_1
docCurrent.Body = docCurrent.Body1
Set rtitem = New NotesRichTextItem( docCurrent, "Body" )
'Call rtitem.AppendText( docCurrent, "Body" )
Call rtitem.AddNewLine( 1 )
Call rtitem.AppendDocLink( db, db.Title )
'Dim docCurrent As NotesDocument
Set docCurrent=source.Document
If docCurrent.pctComplete(0)="100" Then
docCurrent.reqStatus="Complete"
End If
If docCurrent.reqStatus(0)="Complete" Then
docCurrent.pctComplete="100"
End If
'Call docCurrent.Save (True, False)
Call docCurrent.send(False)
Call docCurrent.save(True, True )
End Sub
Subject: RE: Is there a better way to append a doclink?
Oh wait, I see what the problem is now.
You have created 2 body items. This goes back to the problem we talked about earlier where you are creating fields (Subject1, Body1, etc) that are not necessary.
Eliminate Body1 and just call it Body.
Then use the following code for the doc link:
Instead of:
Dim rtitem As NotesRichTextItem
'TOO MUCH CODE IN BETWEEN THE DIM AND SET
…
Set rtitem = New NotesRichTextItem( docCurrent, “Body” )
'Call rtitem.AppendText( docCurrent, “Body” )
Call rtitem.AddNewLine( 1 )
Call rtitem.AppendDocLink( db, db.Title )
Use:
Dim rtitem As Variant
Set rtitem = docCurrent.GetFirstItem( “Body” )
If rtitem.Type = RICHTEXT Then
Call rtitem.AddNewLine( 2 )
Call rtitem.AppendDocLink( db, db.Title )
End If
also, why are you still calling that agent?
Subject: Any ideas?
Actually I do need the contents of Body1 which is text + the doclink. Can anyone advise how this can be done? Basically what I want to do is docCurrent.Body = docCurrent.Body1 + Call rtitem.AppendDocLink( db, db.Title ). Currently I can send either the text or the link but not both.
Thanks for your help!!
Sub Postsave(Source As Notesuidocument)
'Get a handle on the Notes Session
Dim session As New NotesSession
'Get a handle on the Current NotesUIWorkspace
Dim ws As New NotesUIWorkspace
'Get a handle on the uidoc and underlying document
Dim uidoc As NotesUIDocument
Set uidoc=ws.CurrentDocument
'Get a handle on the current database
Dim db As NotesDatabase
Set db = session.CurrentDatabase
'Assign variables
Dim IssueNum As String
Dim SendTo_1 As Variant
Dim docCurrent As NotesDocument
Set docCurrent = uidoc.Document
Dim tmp As String
Dim Assignees As String
Dim agent As NotesAgent
'Dim rtitem As NotesRichTextItem
Set agent = db.GetAgent("Set Sequential Number")
Call agent.run
If docCurrent.Assignees(0) <> docCurrent.tmpAssignees(0) Then
'Present the dialogbox
Call ws.DialogBox( "dlgTest", True, True, True, False, False, False, "Message Content Only")
End If
docCurrent.Form = "Memo"
docCurrent.tmpAssignees=""
docCurrent.SendTo = docCurrent.Assignees
docCurrent.Subject = docCurrent.Subject_1
docCurrent.Body = docCurrent.Body1
Dim rtitem As Variant
Set rtitem = New NotesRichTextItem( docCurrent, "Body" )
Call rtitem.AddNewLine( 1 )
Call rtitem.AppendDocLink( db, db.Title )
Set docCurrent=source.Document
If docCurrent.pctComplete(0)="100" Then
docCurrent.reqStatus="Complete"
End If
If docCurrent.reqStatus(0)="Complete" Then
docCurrent.pctComplete="100"
End If
Call docCurrent.Save (True, False)
Call docCurrent.send(False)
End Sub
Subject: RE: Is there a better way to append a doclink?
Angie,
Reading through your code I think you are making the common mistake of making it harder than it is. Been there, done that.
A few questions and I may be able to streamline it. First, in this case it seems you are simply trying to send a memo with the body field of docCurrent, to the people in the field Assignees on docCurrent, with a subject of the value that is in the Subject_1 field on docCurrent. Looks like the rest of this is changes to docCurrent that don’t effect the memo. If that is correct could you verify for me?
If so, the dialog box is not needed, and I could simplify the code for you greatly with an example.
Thanks, Norman
Subject: RE: Is there a better way to append a doclink?
Norman,
Don’t send her back to the starting gate. She has been great to work with and given her requirements, this is the point we have gotten to. I would hate to confuse the issue even more.
Subject: RE: Is there a better way to append a doclink?
I have no clue what you are talking about here FileSave, there was no specs asked for here. I was simply asking for clarification to help her out but it seems you are the only one able to do that, at least in your opinion
Subject: RE: Is there a better way to append a doclink?
Not at all. See my response to you in the other thread.
http://www-10.lotus.com/ldd/nd6forum.nsf/DateAllThreadedweb/370a51d02ff610f385256e6f0044d0a2?OpenDocument
Subject: Norman…
Norman your help has been greatly appreciated and I’m also learning from your input. What you don’t know is that File Save has the actual business requirements that I’m working with and he is painfully aware of my limited LotusScript skill.
I feel guilty monopolizing File Save when he has his own work to do and others he could help. I post for any help from senior level developers with strong development skills such as yourself. Please don’t think your help is unappreciated but “sometimes” File Save has been working on something behind the scenes so to speak.
You guys are all great and this is a tremendous resource available to those of us in the earlier stages of development and haven’t had the benefit of formal training.
Subject: RE: Is there a better way to append a doclink?
Angie,
you have bloated the code some here as you declare and set docCurrent 2 times.
Go ahead and send me the database as is (zipped please) so I can see what you are referring to about the text overwriting.
Subject: Variant does not contain an object
A few things about this. First, you said it is PostOpen, but the code is from PostSave. Not a problem, but it is a little different. See the amended version below of your code for a better usage of the value of Source (the NotesUIDocument) passed to you by defualt, which leads to not needing to set it:
Your code:
Sub Postsave(Source As Notesuidocument)
Dim uidoc As NotesUIDocument
Set uidoc=ws.CurrentDocument
If docCurrent.pctComplete(0)=“100” Then
Call docCurrent.FieldSetText _
( “reqStatus”, “Complete” )
End If
End Sub
Amended version:
Sub Postsave(Source As Notesuidocument)
Dim uidoc As NotesUIDocument
Set uidoc=ws.CurrentDocument
If Source.document.pctComplete(0)=“100” Then
Call Source.FieldSetText _
( “reqStatus”, “Complete” )
End If
End Sub
Subject: RE: Variant does not contain an object
oops, my reply was messed up. Try this again!!
Amended version:
Sub Postsave(Source As Notesuidocument)
If Source.document.pctComplete(0)=“100” Then
Call Source.FieldSetText _
( “reqStatus”, “Complete” )
End If
End Sub
An additional note about this. Your pctComplete field in the case of your code looks like it is a text field. I normally use number fields for percentages simply becuase it allows me to manipulate other fields easier, using the field value with no translation.
If you used a number field, your code would look like this:
If Source.document.pctComplete(0)=100 Then
Call Source.FieldSetText _
( “reqStatus”, “Complete” )
End If
Subject: RE: Variant does not contain an object
You evil shortcut taker!!!
I say this because I absoluttely hate to see code posted such as
“Source.document.pctComplete(0)=100”
It might be all well and good for an experienced coder but does nothing to help a new coder such as Angie think through the object model when coding (and can also lead to bad habits down the road).
Subject: RE: Variant does not contain an object
I agree on some points, and disagree on others. If what you say is true, then almost all Java and javascript code that exists is written badly, and will lead to bad habits.
I prefer to think of it along the lines of learning the object model. In this case, that will do that, dot notation is the best way to do it.
Subject: Source.document.pctComplete(0)?
I’m really trying to understand LotusScript so can you please tell me where the document comes in with your code? I guess I’d have coded it simply source.pctComplete. What does .document do or mean? Thanks!
If Source.document.pctComplete(0)=“100” Then
Subject: RE: Source.document.pctComplete(0)?
Sure. This is something that as you get deeper into script you will see often, when doing front end script. What is happening is that you have a variable that contains the NoteUIDocument object (Source), and you want to read a field value from the underlying NotesDocument object. In Notes, each document opened in the UI has an equivalent separate version accessable from the back end (on disk if it has been saved) as a NotesDocument object. One of the ways you can do that is to use the NotesUIDocument (Source) to get a handle on that object.
So, Source is a NotesUIDocument object, Source.document is the equivalent NotesDocument object. By saying Source.document.pctComplete(0) you are asking for the first (and only) value of the pctComplete field off of the NotesDocument.
Hope that helps
Subject: RE: Source.document.pctComplete(0)?
Norman,
This is exactly what I was referring to and why I feel shortcuts can be dangerouse as it is not always clear on the face what is being done.
JavaScript and Java are diffrent animals than LotusScript for a number of reasons and I think all Java code is bad by definition;-) .
Subject: RE: Source.document.pctComplete(0)?
Appreciate your opinion on this, honestly. Myself, I don’t look at it as a shortcut, but as a wiser use of the code. In this case, Why create a NotesDocument object when all you are trying to do is get the value of one field? That is waistfull in cases where you are trying to write highly scalable code.
Your opinions on JavaScript and Java are not unique, however they are becoming a fact of life for people such as myself who work with many different developers, companies, infrastructures and types of applications.
Regardless, thanks for your input.