Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create New Document

Status
Not open for further replies.

freak11

Programmer
Jun 16, 2006
20
MX
Hi...
here is my thingy... i find this script somewhere in this forum posted by pmonett...

dim session as new notessession
dim db as notesdatabase
dim doc as notesdocument

set db = session.currentdatabase
set doc = db.createdocument
'set various fields here
'
'now set the form to be used
doc.form = "Component Pulp"
'finally, save the document
call doc.save(true,false,true)


it works perfectly... but i want to know if theres is a way to get the values for the field from a view... for example... look in a view in a certain Column, in a certain Row and set
doc.field = row,column,view (specifiin what view and what row and column is the value)

tnx for ur time

 
A view is a listing of documents that meet the view criteria. So what you really want is to take the information from an existing document and include that in the new document. Do you know the criteria the view is using to find the relevant document? Is there a SINGLE document in the view?

Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for anyone working with databases: The Fundamentals of Relational Database Design
 
What you might be looking for is the ViewEntry object. Look it up in the Designer Help db, I'm sure you're going to find it interesting.

Pascal.
 
well... tnx both for answering... ill be more specific
i have a view with names of employes, mail, number, a course the employe went, date of the course, date when the course ends and some more information about this employes, this docs wer saved in a form, now i need to make an agent that create a new doc with some of this information (wish is a survey about the course) the date when the course ends and send a mail to this employe with a link to the doc so he can answer the survey. Thats pretty much it... i think... btw. i just startd with lotus about 1 mount ago.. so i aint a PRO, ill really apreciate all the help as posible so i can become a PRO PRO :p

tnx
 
Thank you for the additional information.
You'll still be using NotesViewEntryCollection and NotesViewEntry to build your Survey document.
Remember to save the document before sending the mail. Also, do not forget to make sure that the database has a default form and a default view. Taking care of that early will remove some problems you can run into later.
You have a fun little project to start with. Good luck !

Pascal.
 
thank you very much :)
the bad thing is that a broke my shoulder this weekend... so i think i wont work as much for 3 weeks...
when i really get into it... ill let you know how it workd, and ask you if i need some more help :)

tnx for the help so far
 
Hi again... im working 1 handed... is not the best way... but im trying :)
here is the script i just made (workd perfectly

Sub Click(Source As Button)
Dim doc As NotesDocument
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim entry As NotesViewEntry
Set db = session.CurrentDatabase
Set view = db.GetView("completa2")
Set entry = view.GetEntryByKey("Luis Ruiz Soto")
Set doc = New NotesDocument(db)
doc.Form = "encuesta1"
doc.nombre1 = entry.ColumnValues(0)
doc.rpe1 = entry.ColumnValues(2)
doc.departamento1 = entry.ColumnValues(3)
doc.curso1 = entry.ColumnValues(5)
Call doc.Save (True, False,False)
End Sub [\b]

now.. i gotta send a link for this doc just created to a mail... the mail is saved in doc.nombre1 up there

could you help with that plz
 
ouch... now that i think bout it is not this easy...
the the key for the entry is gonna be a date that is in this same view... and the doc is gonna be created if this date is 10 days after @NOW
 
Once the doc is saved, sending a link is easy. Create yourself another document object (maildoc), and fill in the proper fields (sendto, subject). Create a NotesRichText object and use it to create the link to your newly-saved document.
Once you have that, you can send off Maildoc and the recipient will get the link.

Pascal.
 
Here is the code im using...
Code:
Sub Click(Source As Button)
	Dim doc As NotesDocument
	Dim session As New NotesSession
	Dim db As NotesDatabase
	Dim view As NotesView
	Dim entry As NotesViewEntry
	Set db = session.CurrentDatabase
	Set view = db.GetView("completa2")
	Set entry = view.GetEntryByKey("Luis Ruiz Soto")
	Set doc = New NotesDocument(db)
	doc.Form = "encuesta1"
	doc.nombre1 = entry.ColumnValues(0)
	doc.rpe1 = entry.ColumnValues(4)
	doc.departamento1 = entry.ColumnValues(5)
	doc.curso1 = entry.ColumnValues(7)
	doc.puesto1 = entry.ColumnValues(6)
	doc.fechacurso = entry.ColumnValues(1)
	doc.fechacurso_1 = entry.ColumnValues(2)
	doc.capacitacion1 = entry.ColumnValues(8)
	'doc.atrabajo1 = entry.ColumnValues(9)
	Call doc.Save (True, False,False)
	Call doc.Send(False, "Carlos Nava Aviles")
End Sub
i tried with doc.Send...
Carlos Nava Aviles is my mail address..
i do receive the mail but when i open it it sais:
"Cant find form encuesta1"
so the mail is empty
whys is that?
btw.. i didnt get the way u told me (maildoc)...
i look for some more help in Lotus help with no good results
so ill apreciate if u coul be more specific :)
thank you very much
 
Code:
Sub Click(Source As Button)
	Dim doc As NotesDocument
	Dim session As New NotesSession
	Dim db As NotesDatabase
	Dim view As NotesView
	Dim entry As NotesViewEntry
	Set db = session.CurrentDatabase
	Set view = db.GetView("completa2")
	Set entry = view.GetEntryByKey("Carlos Nava Aviles")
	Set doc = New NotesDocument(db)
	doc.Form = "encuesta1"
	doc.nombre1 = entry.ColumnValues(0)
	doc.rpe1 = entry.ColumnValues(4)
	doc.departamento1 = entry.ColumnValues(5)
	doc.curso1 = entry.ColumnValues(7)
	doc.puesto1 = entry.ColumnValues(6)
	doc.fechacurso = entry.ColumnValues(1)
	doc.fechacurso_1 = entry.ColumnValues(2)
	doc.capacitacion1 = entry.ColumnValues(8)
	'doc.atrabajo1 = entry.ColumnValues(9)
	Call doc.Save (True, False,False)
	Call doc.Send(True, entry.ColumnValues(0)) ' Envia el correo a la persona especifica
End Sub

ok... i have this code... works for me...it creates a new doc and send it to a mail adress... well.. this doc shoould be created when "@Now > entry.ColumnValues(12) + 10" where entry.ColumnValues(12) is a date value ... so the doc is gonna be created 10 days after this date (i dont know how to do this condition) so i need help with creatin an agent that runs every night and create all docs where "@Now > entry.ColumnValues(12) + 10"
As u can see my english is not perfect.. so you may not understand everythin o write. so plz let me know so i try to xplain it teh best i can :p
tnx for ur time
 
This is not a big problem. The best way to do it is to create a hidden view that contains all docs not yet treated that have been created more than X days ago.
Once that view is correct, all you need is an agent that iterates over all docs, and one by one does what is needed.

That is the principle. There is one trap : when iterating, you cannot use GetNextDocument once the working doc has been updated. Indeed, you will need to set a flag that indicates that the document has been treated, which, when you save it, will take the doc out of the view.
The answer is to simply use GetFirstDocument every time, since the old FirstDocument will have gone out of the view by itself.

Hope this helps,

Pascal.
 
well i got the date condition. my question is...
u said i gotta set a flag in docs for treated docs... i need to add a new field and edit all docs i have already?

btw... tnx for answering :D ur helpin so much
 
Theoretically, you could use the UpdateProcessedDoc method to mark it as treated by the agent, but if the doc is modified in any way, that will make the agent run on it again, thus potentially creating multiple and useless notifications.
So it is better to set a field value - even if you do have to modify all docs that do not need to be treated by the agent. You can easily set field values with a Simple Agent, and run on All Selected docs to update them.

The help is normal - we've all been there before. And right now, I'm scheduled to be there again since I'm taking up Java to integrate a Java development team.
So I'll be the one with all the questions ! ;-)

Pascal.
 
hey... i have another question :)

how do i make the iterations??

i thought could be this way.. lets me know if im right or wrong. or WAY WRONG :p

Code:
while(entry != NULL)
        Set entry = view.GetFirstEntry
	Set doc2 = entry.Document 
	doc2.Form = "encuesta2"
	doc2.flag2 =1 'takes it out of the view
	Call doc2.Save (True, False,False)
	Set doc = New NotesDocument(db)
	doc.Form = "encuesta1"
	doc.nombre1 = entry.ColumnValues(0)
	doc.rpe1 = entry.ColumnValues(4)
	doc.departamento1 = entry.ColumnValues(5)
	doc.curso1 = entry.ColumnValues(7)
	doc.puesto1 = entry.ColumnValues(6)
	doc.fechacurso = entry.ColumnValues(1)
	doc.fechacurso_1 = entry.ColumnValues(2)
	doc.capacitacion1 = entry.ColumnValues(8)
	doc.flag1 = 0
	doc.subject = " Encuesta"
	Call doc.Save (True, False,False)
	Call doc.Send(True, entry.ColumnValues(0)) 
WEND
im not sure of the NULL thingy
how do i make it stop when there are no more entrys in the view?
and let me know if that condition is right? or what could i use? do...until
plz help :-D

TNX
btw... good luck with ur Java Dv Team [thumbsup2]
 
Actually, to iterate through a view I simply use a do..loop and test on the document itself.

For example :
Code:
Set doc = view.GetFirstDocument
Do While Not(Doc is Nothing)
    ...
    Set olddoc = doc
    Set doc = view.getNextDocument(olddoc)
    Delete olddoc
Loop

As you can see, I use a temp doc to "store" the current doc reference before switching to the new one, then I delete it. That's a habit I took one day back in R4 time, when I had an enormous view that suddenly started crashing my code because of an Out Of Memory error. Doing this fixed it.
For the rest, Null is not good for testing whether an object exists or not. Most of the time, you will need to use Nothing, or test if the value is empty.

Pascal.
 
Well... lets see if i got it...
olddoc is an Entry?
docu is used only for the condition??
is that condition right (docu is Nothing)??
when i do: Set entry = view.GetFirstEntry its because the oldfirst entry is already gone from the view... am i right?

i think thats ir for now... hope i got it right.. if not... shame :~/
[sadeyes]
so i dont feel bad let me remind you all iv learn about lotus is what i read last 3 mounths... so im not really good at this... so plz be patient :-D
Code:
Dim doc As NotesDocument
Dim doc2 As NotesDocument
Dim docu As NotesDocument
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim entry As NotesViewEntry
Dim oldcoc As NotesViewEntry
Set db = session.CurrentDatabase
Set view = db.GetView("completa2")
Set docu = view.GetFirstDocument
Do While Not(docu is Nothing)
    Set olddoc = docu
    Set docu = view.getNextDocument(olddoc)
    Delete olddoc
    Set entry = view.GetFirstEntry
    Set doc2 = entry.Document
    doc2.Form = "encuesta2"
    doc2.flag2 =1 'takes it out of the view
    Call doc2.Save (True, False,False)
    Set doc = New NotesDocument(db)
    doc.Form = "encuesta1"
    doc.nombre1 = entry.ColumnValues(0)
    doc.rpe1 = entry.ColumnValues(4)
    doc.departamento1 = entry.ColumnValues(5)
    doc.curso1 = entry.ColumnValues(7)
    doc.puesto1 = entry.ColumnValues(6)
    doc.fechacurso = entry.ColumnValues(1)
    doc.fechacurso_1 = entry.ColumnValues(2)
    doc.capacitacion1 = entry.ColumnValues(8)
    doc.flag1 = 0
    doc.subject = " Encuesta"
    Call doc.Save (True, False,False)
    Call doc.Send(True, entry.ColumnValues(0)) 
Loop
 
Umm, olddoc is a notesdocument, like doc.
I use it to switch from one doc to the next.

You can do the same with NotesViewEntry, of course.

Don't worry, nobody is blaming you for beginning :).

Pascal.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top