On the topic of custom fields, things have evolved a fair bit over time and we have some methods of convenience to make it easier to get and set custom field values - you may or may not be aware of them.
Firstly, there is the GetValue generic method:
- Code: Select all
Public Function GetValue(Of T)(Name As String, DefaultValue As T) As T
An example of using it to get a sales order line custom field value for a checkbox custom field named "IsWarrantyItem" :
- Code: Select all
Dim IsWarranty As Boolean = SalesOrderLine.CustomFieldValues.GetValue(Of Boolean)("IsWarrantyItem", False)
We do all the conversions for you and return the appropriate value of the appropriate type - including a default value if none was ever set.
There is the expected SetValue method also, which is the inverse of the above - to set the custom field value:
- Code: Select all
Public Overloads Sub SetValue(Of T)(Name As String, NewValue As T)
An example of setting a value to True:
- Code: Select all
SalesOrderLine.CustomFieldValues.SetValue(Of Boolean)("IsWarrantyItem", True)
And what if you don't have a sales order line, but you want to get the value of a custom field? There are shared (static in c#) helper methods to assist:
- Code: Select all
Public Shared Function ReadCustomFieldValue(Manager As JiwaApplication.Manager, CustomFieldModuleName As String, ID As String, SettingName As String) As String
Which could be used with the previous examples like:
- Code: Select all
Dim isWarrantyItem As String = JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomFieldValueCollection(Manager, "Sales Order Line", "56584b8c4f8744c3af06", "IsWarrantyItem")
In the above example, "Sales Order Line" is the ModuleName from SY_PluginCustomSettingModules - that's the list of Modules seen on the Custom Fields of the Plugin Maintenance form.
"56584b8c4f8744c3af06" is the Sales order invoice line id (SO_Lines.InvoiceLineID) and "IsWarrantyItem" is the custom field name.
There are other overloads of the method ReadCustomFieldValue, but the above is probably the easiest to use.