Copy items from existing form to a new form

I am trying to have an action button in a form create a new document using the same form and then copy only certain fields of information from the open document over to the new document. Below is the code I’ve pieced together from reading the forum. I’m missing something somewhere but I’m not sure what. For the sake of discussion lets say the form name is “Plant Survey” and the fields of data to copy from docA to docB are “Plant Name”, “Address”, and “City”. (I’ll actually end up wanting to copy over about 10 fields of data the new doc).

MY SCRIPT:

Sub Click(Source As Button)

      ' creates a new document and puts information into new form

Dim session As New notessession

Dim workspace As New NotesUIWorkspace

Dim Item As NotesItem

Dim DateTime As NotesDateTime, BlankDate As NotesDateTime

Dim db As notesdatabase

Dim uidoc As NotesUIDocument

Dim docA As notesdocument

Dim docB As NotesDocument

Set uidoc = workspace.CurrentDocument

Set db=session.currentdatabase

 ' DocA - original  DocB is the copy

Set docA =uidoc.Document  

Set docB = New NotesDocument(db)

 ' Set Date to Today

Set dateTime = New NotesDateTime ("Today")

Set BlankDate = New NotesDateTime(" ")

 'Must be in edit mode to copy document

If Not uidoc.EditMode Then

	uidoc.EditMode = True       

End If

docB.form = "Plant Survey"

Set item = doc.GetFirstItem("Plant_Name")

Call item.CopyItemToDocument(docB, "Plant_Name")

Set item = doc.GetFirstItem("Address")

Call item.CopyItemToDocument(docB, "Address")

Set item = doc.GetFirstItem("City")

Call item.CopyItemToDocument(docB, "City")

Call docB.Save(True, False)

 'Set new information for field that has document create date

Set docB.SurveyDate = dateTime

Call docB.Save (True,False)  

If uidoc.EditMode Then

	uidoc.EditMode = False

End If

Msgbox "CAUTION!!  You have just copied the data contents of this survey into a new plant survey form.",,"Advisory"

End Sub

Thanks in advance.

Lee

Subject: Copy items from existing form to a new form

	Dim session As New NotesSession

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim newuidoc As NotesUIDocument



Dim db As NotesDatabase

Dim docA As NotesDocument

Dim docB As NotesDocument



Set uidoc = ws.CurrentDocument	

Set db = session.CurrentDatabase

Set docA = uidoc.Document



Set docB = New NotesDocument( db )

docB.Form="SysProblemLog"

Call docA.CopyAllItems( docB, True )



Call docB.ReplaceItemValue("ProblemLogType", "Management" )

Call docB.ReplaceItemValue("MainUNID",docA.UniversalID)

Call docB.ReplaceItemValue("$PaperColor", 24 )

Call docB.RemoveItem( "$PaperColorEx" )



Set newuidoc = ws.EditDocument(True, docB)

Subject: RE: Copy items from existing form to a new form

Thanks for the example, but a question poses itself. I’m new to Lotus Script, but if I read your example right, it is copying the whole document for docA to docB (all fields), and then trying to edit them afterwards. The document I’m dealing with has over 100 fields of info and that is why I’m trying to avoid copying Allitems over to docB (changing or replacing items on docB would be too cumbersome). Maybe it is not possible to do what I’m attempting?

Sincerely,

Lee

Subject: RE: Copy items from existing form to a new form

Well folks, after spending some time reading this forum and then going back to my Lotus design books, I figured this out using formula language instead of Lotus script. This may not be the most efficient way, but it works great and fast using an action button. The form actually has over 200 fields, but remember, I only wanted to copy over data from the first ~30. After a user opens a new document using the desired form, they can click on an action button(button only appears if @isnewdoc), that will let them choose from a list of previous documents. (choice list is presented in a view that has uniquedocid hidden in the first column.) The uniquedocid is used to then populate the desired fields of the new document using @getdocfield

<<>>>>

REM {choose the facility to pull general information from. Value returned is the document’s unique ID from column 1. this is done in case plant name is same};

temp1:= @PickList([Custom]:[Single];“”:“”;“AllFacilitiesView”;“Plants Surveyed”;“Sort alphabetically by clicking on the column header for plant names, then select the plant you wish to copy data from:”;1);

REM {use the document unique ID in column one as the key for picking the other desired field values from the source document and insert them into the fields on the new document};

FIELD Plant_Name:= @GetDocField(temp1;“Plant_Name”);

FIELD Address:= @GetDocField(temp1;“Address”);

FIELD City:=@GetDocField(temp1;“City”);

FIELD State:=@GetDocField(temp1;“State”);

FIELD Zip:=@GetDocField(temp1;“Zip”);

FIELD Office:=@GetDocField(temp1;“Office”);

FIELD Contract:=@GetDocField(temp1;“Contract”);

FIELD Product:=@GetDocField(temp1;“Product”);

FIELD Mailing_Address:=@GetDocField(temp1;“Mailing_Address”);

FIELD Mailing_City:=@GetDocField(temp1;“Mailing_City”);

FIELD MaiingState:=@GetDocField(temp1;“MailingState”);

FIELD MailingZip:=@GetDocField(temp1;“MailingZip”);

FIELD Location:=@GetDocField(temp1;“Location”);

FIELD Location_City:=@GetDocField(temp1;“Location_City”);

FIELD LocationState:=@GetDocField(temp1;“LocationState”);

FIELD LocationZIP:=@GetDocField(temp1;“LocationZIP”);

FIELD Proprietorship:=@GetDocField(temp1;“Proprietorship”);

FIELD OtherOwner:=@GetDocField(temp1;“OtherOwner”);

FIELD Other:=@GetDocField(temp1;“Other”);

FIELD Name1:=@GetDocField(temp1;“Name1”);

FIELD Name2:=@GetDocField(temp1;“Name2”);

FIELD Name3:=@GetDocField(temp1;“Name3”);

FIELD Name4:=@GetDocField(temp1;“Name4”);

FIELD Name5:=@GetDocField(temp1;“Name5”);

FIELD Name6:=@GetDocField(temp1;“Name6”);

FIELD Name7:=@GetDocField(temp1;“Name7”);

FIELD Name8:=@GetDocField(temp1;“Name8”);

FIELD Name9:=@GetDocField(temp1;“Name9”);

FIELD Name10:=@GetDocField(temp1;“Name10”);

FIELD Name11:=@GetDocField(temp1;“Name11”);

FIELD Name12:=@GetDocField(temp1;“Name12”);

FIELD Name13:=@GetDocField(temp1;“Name13”);

FIELD Name14:=@GetDocField(temp1;“Name14”);

FIELD Name15:=@GetDocField(temp1;“Name15”);

FIELD Name16:=@GetDocField(temp1;“Name16”);

FIELD Name17:=@GetDocField(temp1;“Name17”);

FIELD Name18:=@GetDocField(temp1;“Name18”);

FIELD Name19:=@GetDocField(temp1;“Name19”);

FIELD Title1:=@GetDocField(temp1;“Title1”);

FIELD Title2:=@GetDocField(temp1;“Title2”);

FIELD Title3:=@GetDocField(temp1;“Title3”);

FIELD Title4:=@GetDocField(temp1;“Title4”);

FIELD Title5:=@GetDocField(temp1;“Title5”);

FIELD Title6:=@GetDocField(temp1;“Title6”);

FIELD Title7:=@GetDocField(temp1;“Title7”);

FIELD Title8:=@GetDocField(temp1;“Title8”);

FIELD Title9:=@GetDocField(temp1;“Title9”);

FIELD Title10:=@GetDocField(temp1;“Title10”);

FIELD Title11:=@GetDocField(temp1;“Title11”);

FIELD Title12:=@GetDocField(temp1;“Title12”);

FIELD Title13:=@GetDocField(temp1;“Title13”);

FIELD Title14:=@GetDocField(temp1;“Title14”);

FIELD Title15:=@GetDocField(temp1;“Title15”);

FIELD Title16:=@GetDocField(temp1;“Title16”);

FIELD Title17:=@GetDocField(temp1;“Title17”);

FIELD Title18:=@GetDocField(temp1;“Title18”);

FIELD Title19:=@GetDocField(temp1;“Title19”);

FIELD CodingType:=@GetDocField(temp1;“CodingType”);

FIELD Coding_1:=@GetDocField(temp1;“Coding_1”);

FIELD Coding_2:=@GetDocField(temp1;“Coding_2”);

FIELD OtherStatus:=@GetDocField(temp1;“OtherStatus”);

FIELD Othercoding:=@GetDocField(temp1;“OtherCoding”);

FIELD What:=@GetDocField(temp1;“What”);

FIELD Labels:=@GetDocField(temp1;“Labels”);

FIELD Commodity:=@GetDocField(temp1;“Commodity”);

FIELD Commodity_1:=@GetDocField(temp1;“Commodity_1”);

FIELD Commodity_2:=@GetDocField(temp1;“Commodity_2”);

FIELD Commodity_3:=@GetDocField(temp1;“Commodity_3”);

FIELD Commodity_4:=@GetDocField(temp1;“Commodity_4”);

FIELD Commodity_5:=@GetDocField(temp1;“Commodity_5”);

FIELD Commodity_6:=@GetDocField(temp1;“Commodity_6”);

FIELD Commodity_7:=@GetDocField(temp1;“Commodity_7”);

FIELD Commodity_8:=@GetDocField(temp1;“Commodity_8”);

FIELD Commodity_9:=@GetDocField(temp1;“Commodity_9”);

FIELD Season:=@GetDocField(temp1;“Season”);

FIELD Season_1:=@GetDocField(temp1;“Season_1”);

FIELD Season_2:=@GetDocField(temp1;“Season_2”);

FIELD Season_3:=@GetDocField(temp1;“Season_3”);

FIELD Season_4:=@GetDocField(temp1;“Season_4”);

FIELD Season_5:=@GetDocField(temp1;“Season_5”);

FIELD Season_6:=@GetDocField(temp1;“Season_6”);

FIELD Season_7:=@GetDocField(temp1;“Season_7”);

FIELD Season_8:=@GetDocField(temp1;“Season_8”);

FIELD Season_9:=@GetDocField(temp1;“Season_9”);

FIELD SurveyDate:=@Today;

@Prompt([Ok]; “Facility Copied”;“Only certain general information fields from the plant you selected will be copied to this form. No survey answers are copied from the previous survey”);

@True