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

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?
RhodyRichAtlAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sjef BosmanGroupware ConsultantCommented:
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?
0
RhodyRichAtlAuthor 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.
0
Sjef BosmanGroupware ConsultantCommented:
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
...
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

RhodyRichAtlAuthor 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".
0
Sjef BosmanGroupware ConsultantCommented:
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.
0
RhodyRichAtlAuthor 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
0
Sjef BosmanGroupware ConsultantCommented:
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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RhodyRichAtlAuthor Commented:
Help was good but not specific enough.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.