Lotuscript problem

Hi To all of you and happy Chtistmas

I have a little Lotusscript problem!

I have to docs I want to take the data from those two and create a new doc with the data! So i wrote a little piece of code!

But i got the error message Object variable not set! Here is the code :

Thanks Branimir

    Dim s As New NotesSession

Dim ugView As NotesView

Dim rnView As NotesView

Dim ug As NotesDocument

Dim rn As Notesdocument

Dim newDoc As NotesDocument

Dim jmbg As String



Set db = s.CurrentDatabase

Set rnView = db.GetView("ZaMAriaNalogKabel")



Set ugView = db.GetView("ZaMariaUgovori")

Set ug = ugView.GetFirstDocument

'While Not (ug Is Nothing) 

Set ug = ugView.GetNextDocument(ug)

Messagebox aaaa,,b

jmbg=ug.jmbg(0)



Set rn = ugView.GetDocumentByKey(jmbg,True)

Set newDoc = New NotesDocument(db)

newDoc.form = "ZaMaria"



newDoc.kom = ug.komitent

newDoc.adr=rn.adresa

newDoc.jmbg=jmbg



newDoc.ComputeWithForm False,True          

Call newDoc.Save(False,False)	

'Wend

Subject: Lotuscript problem

A couple of things.

  1. turn on the debugger, and find out which line is causing the problem

  2. on the line:

newDoc.kom = ug.komitent

…I dont understand what “komitent” is.

  1. on the line:

newDoc.adr = rn.adresa

…try newDoc.adr = rn.adresa(0)

Again, turn on the debugger, and it should show you which object variable is not set.

  • Matt

Subject: RE: Lotuscript problem

Hi Matt I have made some changes to the code and realized that my Set rn = rnView.GetDocumentByKey(key)

line of code doesnt work rn is nothing

When I only use the data from ug it works just fine!

And i have to use variant to get the value key

key=ug.GetItemValue(“jmbg”)

otherwise it says Type mismatch!

HEEEEEEEEELP

Here is the new code!

Dim s As New NotesSession

Dim db As NotesDatabase

Dim ugView As NotesView

Dim rnView As NotesView

Dim ug As NotesDocument

Dim rn As Notesdocument

Dim newDoc As NotesDocument

Dim key As Variant



Set db = s.CurrentDatabase



Set rnView = db.GetView("ZaMAriaNalogKabel")

If (rnView Is Nothing) Then

	Messagebox "Nisam Pronašao View-ZaMariaNalogKabel"

	Exit Sub

End If



Set ugView = db.GetView("ZaMariaUgovori")

If (ugView Is Nothing) Then

	Messagebox "Nisam Pronašao View-ZaMariaUgovori"

End If



Set ug = ugView.GetLastDocument







'While Not (ug Is Nothing) 

key=ug.GetItemValue("jmbg")



Set rn = rnView.GetDocumentByKey(key)

If Not (rn Is Nothing) Then

	Messagebox "JMBG=" & jmbg,,"JMBG	"	

Else

	Messagebox "Nisam pronašao odgovarajući radni nalog",, "Greška"

End If

Set	newDoc = db.CreateDocument



newDoc.form = "ZaMaria"

newDoc.kom = ug.GetItemValue("organizacija")

newDoc.adr=ug.getitemvalue("adresadobavljac")

newDoc.jmbg=key

newDoc.ComputeWithForm False,True          

Call newDoc.Save(False,False)

Subject: RE: Lotuscript problem

Hi Matt and thank you for your fast response.

  1. I am not sure how to do it(turn on the debuger) the only thing i can do in designer is Recompile all lotusscript!

  2. komitenti is a field on the doc ug that holds the name and surname of a customer

I am not sure if I get the jmbg out of the doc ug correctly, and do I find the doc rn from the other view correctly! Its my first time writing a code that does something that I cant see(backend)! Is this part of the code correct(Choosing the right documents)?

Thank you again

Subject: RE: Lotuscript problem

Hi

One of the most important commands in backend agents is Msgbox…it writes to the Notes log.

The way to find out which line is going wrong is to use this with some error handling. Something like…

Sub Initialize

On Error Goto errorTrap

//Your code goes here

Exit Sub

errorTrap:

Msgbox "Error: " & Error$ & " at line " & Cstr(erl)

Exit Sub

End Sub

Run the code then check the Notes log on the server. You should see a line something like:

Agent Message: Error: Object Variable not set at line 27

Magic eh? Personally it’s the first lines I write in any web or background agent.

Hope this helps

Pete

Subject: Lotuscript problem

You’ve remmed out your loop but that should not be causing that error. All notes fields are array’s so you need to add a (0) to two of your lines. See the Bold in the code below. I don’t know what’s up with your message box as I don’t see you setting a value for aaaa or b for that matter.

To get into the debugger it’s under the file menu…

Dim s As New NotesSession

Dim ugView As NotesView

Dim rnView As NotesView

Dim ug As NotesDocument

Dim rn As Notesdocument

Dim newDoc As NotesDocument

Dim jmbg As String



Set db = s.CurrentDatabase

Set rnView = db.GetView("ZaMAriaNalogKabel")



Set ugView = db.GetView("ZaMariaUgovori")

Set ug = ugView.GetFirstDocument

'While Not (ug Is Nothing) 

Set ug = ugView.GetNextDocument(ug)

Messagebox aaaa,,b

jmbg=ug.jmbg(0)



Set rn = ugView.GetDocumentByKey(jmbg,True)

Set newDoc = New NotesDocument(db)

newDoc.form = "ZaMaria"



newDoc.kom = ug.komitent(0)

newDoc.adr=rn.adresa(0)

newDoc.jmbg=jmbg



newDoc.ComputeWithForm False,True          

Call newDoc.Save(False,False)

Subject: RE: Lotuscript problem

Mr. Leedy could you please take a look at this post:

http://www-10.lotus.com/ldd/nd6forum.nsf/DateAllThreadedweb/0edd640105f50f9185257251004da04e?OpenDocument

Thank you

Subject: RE: Lotuscript problem

Brane,

I’m looking at the New code you posted… I can’t comment on the logic… just really the syntax…

I hope this helps…

Dim s As New NotesSession

Dim db As NotesDatabase

Dim ugView As NotesView

Dim rnView As NotesView

Dim ug As NotesDocument

Dim rn As Notesdocument

Dim newDoc As NotesDocument

Dim key As Variant

Set db = s.CurrentDatabase

Set rnView = db.GetView(“ZaMAriaNalogKabel”)

If (rnView Is Nothing) Then

Messagebox "Nisam Pronašao View-ZaMariaNalogKabel"

Exit Sub

End If

’ It looks like you should correctly have rnView set.

Set ugView = db.GetView(“ZaMariaUgovori”)

If (ugView Is Nothing) Then

Messagebox "Nisam Pronašao View-ZaMariaUgovori"

End If

’ It looks like you should correctly have ugView set.

Set ug = ugView.GetLastDocument

’ Is there a reason why you’re using GetLASTDocument here? Typically people use GetFIRSTDocument.

’ Be advised that this has nothing to do with the ORDER of documents in the VIEW. You’re not actually getting the very

’ Last or First document.

’ However at this poing ug should be a document

'While Not (ug Is Nothing)

’ This is still remarked so we’re not actially looping.

key=ug.GetItemValue(“jmbg”)

’ I don’t typically use “GetItemValue” here. I use the short notation and say:

’ key = ug.jmbg(0)

’ If you insist in using GetItemValue then it should probably look like this:

’ key = ug.GetItemValue(“jmbg”)(0)

'Add This so you at least know what’s happening:

if key = “” then

 messagebox("Key Not Found")

 exit sub

end if

Set rn = rnView.GetDocumentByKey(key)

If Not (rn Is Nothing) Then

Messagebox "JMBG=" & jmbg,,"JMBG	"	

Else

Messagebox "Nisam pronašao odgovarajući radni nalog",, "Greška"

End If

’ I can’t tell the language but if the doc IS nothing then you should add an “Exit Sub” to stop the code from processing.

Set newDoc = db.CreateDocument

newDoc.form = “ZaMaria”

newDoc.kom = ug.GetItemValue(“organizacija”)(0)

newDoc.adr=ug.getitemvalue(“adresadobavljac”)(0)

’ Again add the Zero’s above or switch to shorthand.

’ newdoc.kom = ug.organizacija(0)

’ newdoc.adr = ug.adresadobavljac(0)

newDoc.jmbg=key

newDoc.ComputeWithForm False,True

Call newDoc.Save(False,False)

Subject: Lotuscript problem

Hi to all and thank you for your help I have learned something from each of you!

I have figuered out where the problem is!

The key that I used for GetDocumentByKey was a value that is computed and didnt returned any value! When I tried with another field that is also unique for each document it has worked! How come?

However now I wonder if I can do that agent on all docs in the views, there are about 2000 documents ug and 2000 docs rn that should be merged into one document!

How long is this going to take?

Thank you

Subject: RE: Lotuscript problem

If the field is computed for display, then there shouldn’t be a backend value that you can get. You’d need to make it simply “computed” if it’s not already.

As to how long it’s going to take to loop though and merge documents? I would have no way of knowning, but once the code is done I wouldn’t expect it to take long to run at all.