Solved

Dev problem - automatically populating fields

Posted on 2000-04-10
7
177 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Accepted Solution

by:
srandrews earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Answer accepted
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now