Solved

Dev problem - automatically populating fields

Posted on 2000-04-10
7
185 Views
Last Modified: 2013-12-18
This may be an easy question, but for novices like me, it's one I have lost sleep over...

Let's say there is a field on a parent document called ParentField.  On one of its child documents, there is a field that we'll call ChildField.  As users of the DB create child documents, they'll have to add some value into ChildField.  That's the scenario...

Here's the question... How can I have ParentField automatically populate itself from whatever is in ChildField?  Or I guess you can ask, how can I get ChildField to pass it's value to ParentField?

Thanks!
0
Comment
Question by:steve71
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 7

Expert Comment

by:Z_Beeblebrox
ID: 2700750
Hi,

The easiest way to do this is probably to create a script in the QueryClose event of the child document which will update the parent document using the NotesDocument class. Here is a script which I wrote which creates a child document on QueryClose and populates that document with enough information so that when the user opens up the child document, they can be redirected the parent doc.

Dim doc As NotesDocument
Dim session As New NotesSession
 Dim db As NotesDatabase
Dim childID As String
Set db = session.CurrentDatabase          
If source.FieldGetText("Child") = "" Then
   Set doc = New NotesDocument ( db )
Else
   Set doc = db.GetDocumentByID(source.FieldGetText("Child"))
End If  
doc.Form = "SubItem"
doc.Parent = source.FieldGetText("ID")
Call doc.Save( True, True )
childID = doc.NoteID
Call source.FieldSetText("Child",childID)
Call source.Save

Of couse, in your case you may not know the ID of the parent document, in which case you will have to do a lookup via GetDocumentByKey.

Hope this helps,

Zaphod.
0
 

Author Comment

by:steve71
ID: 2701244
Zaphod:

A lot of this is all Greek to me, so tell me if I am wrong in assuming the following:

Wherever you have something in quotes, I will need to provide that information (specific to my documents).  True?

Otherwise, I can simply cut and copy your script straight into the QueryClose event of my Child document.  True?

Finally, if I have multiple fields, then it's a matter of throwing in multiple If.. Else statements into the script.  True?

Thanks.
0
 
LVL 7

Expert Comment

by:Z_Beeblebrox
ID: 2701329
False,
Maybe true,
False.

To explain this better I will walk you through what my script does.

'These 4 lines are variable declarations.
Dim doc As NotesDocument
Dim session As New NotesSession
Dim db As NotesDatabase
Dim childID As String

' This sets the variable db to be the current database
Set db = session.CurrentDatabase          

' source is defined by the QueryClose event as being the document that is being closed. It is a NotesUIDocument, which is one way a document can be referred to in Lotus Script, the other being NotesDocument. This If statement checks to see if there is a value in the Child field of the source document. If Child is blank then a new NotesDocument is created. If it is not blank, then the child field contains the unique ID of the child document which is opened using GetDocumentByID.
If source.FieldGetText("Child") = "" Then
   Set doc = New NotesDocument ( db )
Else
   Set doc = db.GetDocumentByID(source.FieldGetText("Child"))
End If    

' This sets the form of the new doucment to be "SubItem". You will want to specify your own form.
doc.Form = "SubItem"

'This populates the Parent field in the new document with the value that is in the ID field in the original document. To populate multiple fields, just copy this line a few times and change the Parent and the ID.
doc.Parent = source.FieldGetText("ID")

'This saves the new document
Call doc.Save( True, True )

'this sets a temporary variable to have the uniqueID of the document that is being closed
childID = doc.NoteID

'This sets the field Child on the document that is being closed to have the value of the childID temporary variable.
Call source.FieldSetText("Child",childID)

'This saves the document that is being closed
Call source.Save


Now, this script does not do exactly what you want since you will not know the ID of the parent ( I assume ). Therefore you will have to either look it up or link that that document someother way, probably using GetDocumentByKey. If you want to know how to use this method, look it up in the help. Once you have that, you mentioned that you will also want to append text to a field rather than over write it. To do that, you will first need to read the value of that field to a string variable, then append the extra text to that variable, then write it back to the document.

Good luck,

Zaphod.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Accepted Solution

by:
srandrews earned 100 total points
ID: 2707258
Assuming the child document is a response to the parent document this is the easiest wat to do this.

In the QuerySave event of the child form change the run type from Script to Formula
Then enter the following code:

@Setdocfield($Ref;ParentField;ChildField);

The $Ref is the UNID of the parent document. This will change the value in the parent document every time you change the value in the child doc.

Simon
0
 
LVL 9

Expert Comment

by:Arunkumar
ID: 2707273
Hi Steve,

Try this simple one liner.....

Write this code to update the parent doc from the child doc in the querySave events Formula.  @Functions are really powerfull ain't ?  I have developed a similar functionality in my app and its a charm.

@SetDocField($Ref ; "ParentField" ; ChildField );

The above code overwrites the existing values on the parentdocument.  If you dont want to overwrite but to build a list of values then, Put the following code.

@SetDocField($Ref ; "ParentField" ; @GetDocField($Ref;"ParentField" : ChildField))

Good Luck !

-Arun
0
 
LVL 9

Expert Comment

by:Arunkumar
ID: 2707284
Oops !!!

Simon ! You got it.  

Murphys Law -

"How come it happens only to me ?"

This happened a few times to me by the time i compose my information, someone might have already taken it...

Look at the time of posting...

No Hard Feelings...Take it Easy !!!

:)
Arun

PS: I guess I got the whole syntax of the @SetDocField perfectly with quotes and all those stuff. He He He ...

0
 

Author Comment

by:steve71
ID: 2883084
Answer accepted
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For users on the Lotus Notes 8 Standard client, this article provides information on checking the Java Heap size and adjusting it to half of your system RAM in attempt to get the Lotus Notes 8.x Standard client to run faster.  I've had to exercise t…
You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question