Copy-Method in DataDictionary-Class
Hello to all,
is there any method or way to get a Copy of a current row in a DataDictionary-Object?
I want to get a row for example by searching it with:
[CODE]Send Find of oTest_DD EQ 1[/CODE]
and then i want to get a copy of it as a [B]new[/B] row. Then i would change some informations to handle duplicate records and so on and save it to the database through:
[CODE]Send Request_Save of oTest_DD[/CODE]
For the global file buffer, there exists a command, called:
[CODE]NewRecord table[/CODE]
Thats what i need, but i want to use the advantages of a DataDictionary with the Update- and Backout-Functions and so on...
Does someone knows any way to get this?
Re: Copy-Method in DataDictionary-Class
No. Many discussions on this. You have to create your own code in a subclass to do this.
Re: Copy-Method in DataDictionary-Class
Hi Bernhard,
the most typical way of doing this is perhaps in a DDO, but you can do it in any DD class or object. You can use the NewRecord command and then simply loop through the table.columns to duplicate them.
P.S.: Schönes Motto! ;)
Re: Copy-Method in DataDictionary-Class
Here is something I found on the forum that I am using...
[CODE]
// Contributed by Allan Kim Eriksen of NOVAX A/S
// http://support.dataaccess.com/Forums/showthread.php?42133-Make-a-copy-of-the-current-record-in-a-datadictionary-object.&p=204161#post204161
Procedure DoMakeNewCopy
Integer iMaxField iCurField iDDFile iCurFile iMaxFile iParentFile
Handle hParentDD
RowID rwOld rwCurrentID
RowID[] rwParents
Boolean bFound
String sData
Get Data_Set_Server_Count to iMaxFile
Decrement iMaxFile
For iCurFile from 0 to iMaxFile
Get Data_Set_Server iCurFile to hParentDD
Get CurrentRowId of hParentDD to rwParents[iCurFile]
Loop
Get Main_File to iDDFile
Get_Attribute DF_FILE_NUMBER_FIELDS of iDDFile to iMaxField
Get CurrentRowId to rwOld
Send Clear
Move (FindByRowID(iDDFile, rwOld)) to bFound
If bFound Begin
For iCurFile from 0 to iMaxFile
Get Data_Set_Server iCurFile to hParentDD
Get CurrentRowId of hParentDD to rwCurrentID
If (not(IsSameRowID(rwCurrentID, rwParents[iCurFile]))) Begin
Get Main_File of hParentDD to iParentFile
Send FindByRowId of hParentDD iParentFile rwParents[iCurFile]
End
Loop
For iCurField from 1 to iMaxField
Get_Field_Value iDDFile iCurField to sData
Set Field_Changed_Value iCurField to sData
Loop
Clear iDDFile
End
End_Procedure
[/CODE]
I added this to my own custom DD class.
Re: Copy-Method in DataDictionary-Class
Wow, this just works good! Thanks a lot!
Re: Copy-Method in DataDictionary-Class
It does work well.
Additionally, you can add something like this to change fields after the copy (IOW - right before the End_Procedure):
[code]
Set Field_Changed_Value of oOrdHea_DD Field OrdHea.Packed to "N"
... change others if you wish
Send Request_Save of oOrdHea_DD
[/code]
Re: Copy-Method in DataDictionary-Class
Here's some code that actually uses this method.
[CODE]
Procedure DoCopy
RowID riOriginalID riNewProfileID
Integer iNewProfileId
Boolean bFound
Handle hoProfileLines
Get CurrentRowId to riOriginalID
Begin_Transaction
// procedure in cAuditDataDictionary class
Send DoMakeNewCopy
Set Field_Changed_Value PROFILHD.UID to 0
Set Field_Changed_Value PROFILHD.paid_for to 0
Set Field_Changed_Value PROFILHD.times_printed to 0
Set Field_Changed_Value PROFILHD.delete_count to 0
Set Field_Changed_Value PROFILHD.add_count to 0
Set Field_Changed_Value PROFILHD.total_pages_printed to 0
Send Request_Save
End_Transaction
Move PROFILHD.UID to iNewProfileId
Get CurrentRowId to riNewProfileID
Send Clear
// refind the original profile header so the child records can be found and copied
Move (FindByRowID(PROFILHD.File_Number, riOriginalID)) to bFound
// copy the profile lines
Send DoCopyLines of oPROFILLN_DD iNewProfileId
// now go back to the new profile record
Move (FindByRowID(PROFILHD.File_Number,riNewProfileID)) to bFound
End_Procedure
[/CODE]
In this case it's copying an order header and then the child table records and displaying the new order.
Re: Copy-Method in DataDictionary-Class
Hi Bernhard,
[QUOTE=degger;295109]is there any method or way to get a Copy of a current row in a DataDictionary-Object?[/QUOTE]
There is a thread in the Code Library forum covering this [URL="http://support.dataaccess.com/Forums/showthread.php?42133-Make-a-copy-of-the-current-record-in-a-datadictionary-object&p=204684#post204684"]topic [/URL]which you may find helpful.
Re: Copy-Method in DataDictionary-Class
Chuck,
Have you had any issues with this code since 18.2? My "duplicate Item" button uses it, but it's fubar now, and I'm not sure why, could be 18.2, or it could be just me.
MM.
Re: Copy-Method in DataDictionary-Class
While I'm not Chuck - I have this in a # of 18.2 views/DDs & it's working fine.