Solved

Dev problem - automatically populating fields

Posted on 2000-04-10
7
187 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…

832 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