If you simply define one in the "Custom Fields" tab of the plugin, and then restart Jiwa, you will see the field magically appear on the Creditor Purchases lines grid. All the reading and saving of the custom field value is done for you.
I've attached a plugin that shows how to retrieve a line custom field value using code. In the example, a line custom field called "My CRN" is created on the Creditor Purchases lines grid. When a line is edited a message box is displayed showing the value for "My CRN" for that line.
Handler added:
- Code: Select all
public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm jiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin plugin)
{
if (!(jiwaForm is CreditorCreditAdjustment || jiwaForm is CreditorDebitAdjustment || jiwaForm is CreditorPayment || jiwaForm is CreditorPurchases)) return;
var form = (CRBatchTXPurchases)jiwaForm;
AddColumnCrn(form);
form.CRBatchTransObject.TransLines.DispersalChanged += CRBatchTransObject_TransLines_DispersalChanged;
}
Code that retrieves and displays the line custom field value:
- Code: Select all
public void CRBatchTransObject_TransLines_DispersalChanged(JiwaFinancials.Jiwa.JiwaCRBatchTX.CRBatchDispersal item, System.ComponentModel.PropertyChangedEventArgs e)
{
//Find the custom field value
JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomFieldValue customFieldValue = item.CustomFieldValues.get_ItemFromSettingName("My CRN","Custom Field Demo");
//Display a message if a custom field value exists
if (customFieldValue != null && customFieldValue.Contents != null)
System.Windows.Forms.MessageBox.Show(string.Format("Value of {0}: {1}",customFieldValue.CustomField.PluginCustomField.Name, customFieldValue.Contents));
}
Notes:
1. C# will not intelli-sense the get_ItemFromSettingName method (because it is a property with 2 parameters which c# does not like). The alternative to making a call to get_ItemFromSettingName would be to simply iterate through the collection and matching on CustomFieldValue.CustomField.PluginCustomField.Name thus:
- Code: Select all
Dim myCustomFieldValue as JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomFieldValue = nothing;
For Each CustomFieldValue As CustomFieldValue In Me
If CustomFieldValue.CustomField.PluginCustomField.Name = SettingName AndAlso CustomFieldValue.CustomField.PluginCustomField.CustomFieldCollection.Plugin.Name = PluginName Then
myCustomFieldValue = CustomFieldValue
exit for
End If
Next
2. The creditor purchases batch object is a bit of an ugly duckling - a dispersal collection sits under each line. What you see on the grid isn't really a line, but a dispersal. This is why the line custom field collection hangs off the dispersal class.
3. To *modify* the line custom field value in code, simply push a value into customFieldValue.Contents. It will be saved away to the database when the Creditor Purchase object is saved.
4. Note that there is a difference between a Custom Field collection and a Custom Field *Value* collection.