Given that the two have been configured with the same names, I thought it would be easy enough to just traverse the custom data, find the common name, and then copy it over.
It is, but it took me a little while to figure out that I needed to de-reference the PluginCustomField property to find the matching descriptions:
- Code: Select all
For Each qcf As CustomFields.CustomFieldValue In quote.CustomSettingValues
For Each scf As CustomFields.CustomFieldValue In _salesOrder.CustomFieldValues
If scf.CustomField.PluginCustomField.Name = qcf.CustomField.PluginCustomField.Name Then
scf.Contents = qcf.Contents
scf.DisplayContents = qcf.DisplayContents
End If
Next
Next
It would be handy if CustomFields.CustomFieldValue included 'proxy' properties for the underlying CustomField.PluginCustomField's Name and Description.
So I've added general-purpose extension methods in a shared plugin to achieve the desired effect:
- Code: Select all
<Extension()>
Public Function Description(this As CustomFields.CustomFieldValue) As String
Return this.CustomField.PluginCustomField.Description
End Function
<Extension()>
Public Function Name(this As CustomFields.CustomFieldValue) As String
Return this.CustomField.PluginCustomField.Name
End Function
so I now have:
- Code: Select all
...
If scf.Name = qcf.Name Then
scf.Contents = qcf.Contents
scf.DisplayContents = qcf.DisplayContents
End If
...