custom field object name/description  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

custom field object name/description  Topic is solved

Postby pricerc » Mon Dec 10, 2018 8:53 pm

So I'm wanting to copy custom field data from a quote to the sales order. (header only at this point)

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
...
/Ryan

ERP Consultant,
Advanced ERP Limited, NZ
https://aerp.co.nz
User avatar
pricerc
Senpai
Senpai
 
Posts: 504
Joined: Mon Aug 10, 2009 12:22 pm
Location: Auckland, NZ
Topics Solved: 20

Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 13 guests