Page 1 of 1

Custom field event

PostPosted: Mon Apr 16, 2018 11:20 am
by Riyaz
Hi

I need to have an change event attached to a specific custom field which gets added the Custom Fields tab under PO , basically what am after is that, if the value is chosen / changed on this particular custom field, I'll need to change a specific value on all the line items of the Order tab. Pls advise the possibilities

Re: Custom field event  Topic is solved

PostPosted: Tue Apr 17, 2018 8:11 pm
by SBarnes
Hi Riyaz,

Attached is rough example using a sales order of what you need to do which should translate onto a purchase order fairly easily as both have a generic object collection so that you can look for where values change.

Re: Custom field event

PostPosted: Wed Apr 18, 2018 12:35 pm
by Mike.Sheen
Hi Riyaz,

I'm not sure if Sbarnes solution suits or not - I interpreted the question a little differently.

The attached plugin demonstrates how to detect when a custom field on the purchase order changes, and how to iterate all lines on the purchase order and set a property of each line (in this example I simply set the description of each line to be the value of the custom field).

The code itself is all in the BusinessLogicPlugin class:

Code: Select all
public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogic JiwaBusinessLogic, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
{
   JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder purchaseOrder = (JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder)JiwaBusinessLogic;
   purchaseOrder.CustomFieldValues.Changed += PurchaseOrder_CustomFieldValue_Changed;
}

public void PurchaseOrder_CustomFieldValue_Changed(JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomFieldValue item, System.ComponentModel.PropertyChangedEventArgs e)
{
   if (item.CustomField.PluginCustomField.Name == "TestCustomField")
   {
      JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder purchaseOrder = (JiwaFinancials.Jiwa.JiwaPurchaseOrders.PurchaseOrder)item.CustomFieldValueCollection.CustomFieldCollection.BusinessLogic;
      
      foreach (JiwaFinancials.Jiwa.JiwaPurchaseOrders.Line poLine in purchaseOrder.Lines)
      {
         // Demonstrate setting a property of the purchase order line
         poLine.Description = item.Contents;
      }
   }
}


The plugin provided targets 07.01.00 - but if you need it for an earlier version it should work fine as well.

Re: Custom field event

PostPosted: Wed Apr 18, 2018 5:12 pm
by Riyaz
Thanks both Stuart and Mike for this, I appreciate it