We help IT Professionals succeed at work.

Script needed to copy data from one form to another in the same database

RhodyRichAtl
RhodyRichAtl asked
on
I have a database with two different forms. The forms are similar but the field names in each form are unique to that form. I need to copy data from a document created using one form and assign it to fields in a new document created with the other form. Can someone give me a LotusScript to do this or start me in the right direction?
Comment
Watch Question

Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
Is it to be a new document, or is it to be an open document with data from the existing document? The latter is practically for free, using Formulas inherit values from selected document (2nd tab of the Form Properties). In every field of the form,  the default value should be a formula with only the name of the field. In the view, select an old document and then Create a new one.

Or did you have something else in mind?

Author

Commented:
The data needs to be copied from a current document with one form to a new document with another form. The field names in the first form are different than the field names in the second form.
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
Yep, that's what you said already. I only wanted to know if you needed the data on-screen before saving it, or if you wanted a background process.

Anyway, how far did you get yourself with coding an agent? Here's an example of some code that seems about 50% of what you need: http://www.notes411.com/dominosource/tips.nsf/0/909729CDC576B81A8025717F003FFB00!opendocument. Things to change:
- create a new document
- copy the fields you need from the old document to the new document
- set the Form-field explicitly

E.g.

Set newdoc= New NotesDocument(db)
Set newdoc.Form= "Newformname"
Set newdoc.Somefield= olddoc.Someoldfield
...

Author

Commented:
The example you reference is for copying a document to another database. In my case both forms are in the same database. I created an action using this script. I set both the source and destination to the same database. When it runs I get an error message that "Database MyDatabase.nsf has not been opened yet".
Sjef BosmanGroupware Consultant
CERTIFIED EXPERT

Commented:
I hope you didn't get it wrong, but we're not rent-a-coders for free. You're supposed to do the dirty work, and we'll supply our advice. With the info I gave it shouldn't be too difficult to construct your own agent.

Author

Commented:
The following code worked for me. Thanks for your help.

Sub Click(KZ As Button)
      Dim workspace As New NotesUIWorkspace
      Dim uidoc As NotesUIDocument
      Dim KZDoc As NotesDocument
      Dim SGDoc As NotesDocument
      Set uidoc = workspace.CurrentDocument
      Set KZDoc=uidoc.Document
      Set uidoc = workspace.ComposeDocument("","","SG")
      Set SGDoc = uidoc.Document
      SGDoc.SG_Problem=KZDoc.KN_BeforeText
      SGDoc.SG_Idea=KZDoc.KN_AfterEffectText
      SGDoc.SG_Impacted="Employee"
      SGDoc.SG_Benefit="Can't calculate but will describe below"
      SGDoc.SG_CostPeople="I can do it!"
      SGDoc.SG_CostTime="A day or less"
      SGDoc.SG_CostMoney="Cannot calculate"
      SGDoc.SG_Created=Now()
      SGDoc.SG_Created1=Now()
      SGDoc.SG_Creator=KZDoc.KN_Creator
      SGDoc.SG_Creator1=KZDoc.KN_Creator1
      SGDoc.SG_Department=KZDoc.KN_Department
      SGDoc.SG_Process=KZDoc.KN_Process
      SGDoc.SG_Distribution=KZDoc.KN_Distribution
      SGDoc.Save True,False       
End Sub
Groupware Consultant
CERTIFIED EXPERT
Commented:
Excellent! Code seems okay to me, but I think you could even do everything in the background, the ComposeDocument will open a form in the foreground. Some small modifications to that end:

Sub Click(KZ As Button)
      Dim workspace As New NotesUIWorkspace
      Dim uidoc As NotesUIDocument
      Dim KZDoc As NotesDocument
      Dim SGDoc As NotesDocument
      Set uidoc = workspace.CurrentDocument
      Set KZDoc=uidoc.Document
      Set SGDoc = New NotesDocument(KZDoc.ParentDatabase)
      SGDoc.Form= "SG"
      SGDoc.SG_Problem=KZDoc.KN_BeforeText
      SGDoc.SG_Idea=KZDoc.KN_AfterEffectText
      SGDoc.SG_Impacted="Employee"
      SGDoc.SG_Benefit="Can't calculate but will describe below"
      SGDoc.SG_CostPeople="I can do it!"
      SGDoc.SG_CostTime="A day or less"
      SGDoc.SG_CostMoney="Cannot calculate"
      SGDoc.SG_Created=Now()
      SGDoc.SG_Created1=Now()
      SGDoc.SG_Creator=KZDoc.KN_Creator
      SGDoc.SG_Creator1=KZDoc.KN_Creator1
      SGDoc.SG_Department=KZDoc.KN_Department
      SGDoc.SG_Process=KZDoc.KN_Process
      SGDoc.SG_Distribution=KZDoc.KN_Distribution
      SGDoc.Save True,False      
End Sub

Author

Commented:
Help was good but not specific enough.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.