Page 1 of 1

Import Pre-processor

PostPosted: Wed Mar 30, 2022 1:59 pm
by SBarnes
Is there any way or an event for debtor import screen or inventory import screen to be able to through plugin code to pre-process the fields so say for example someone has accidently formatted say RRP as $699.00 so that you can change it into 699.00?

Re: Import Pre-processor

PostPosted: Wed Mar 30, 2022 6:18 pm
by Mike.Sheen
SBarnes wrote:Is there any way or an event for debtor import screen or inventory import screen to be able to through plugin code to pre-process the fields so say for example someone has accidently formatted say RRP as $699.00 so that you can change it into 699.00?


Add a handler for the ReadEnd event of the JiwaInventory.Import.InventoryImport.DestinationProperties:

Code: Select all
public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaBusinessLogic JiwaBusinessLogic, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
{
   if (JiwaBusinessLogic is JiwaFinancials.Jiwa.JiwaInventory.Import.InventoryImport)
   {
      JiwaFinancials.Jiwa.JiwaInventory.Import.InventoryImport inventoryImport = (JiwaFinancials.Jiwa.JiwaInventory.Import.InventoryImport)JiwaBusinessLogic;
      inventoryImport.DestinationProperties.ReadEnd += DestinationProperties_ReadEnd; // We need to re-add our destination property if the collection is ever re-read.
   }
}


And inside therem override the SetterMethod for the DestinationProperty with the RecID "Inventory.RRPPrice":

Code: Select all
private void DestinationProperties_ReadEnd(object sender, System.EventArgs e)
{
    JiwaFinancials.Jiwa.JiwaInventory.Import.DestinationPropertyCollection destinationPropertyCollection = (JiwaFinancials.Jiwa.JiwaInventory.Import.DestinationPropertyCollection)sender;
    destinationPropertyCollection["Inventory.RRPPrice"].SetterMethod = delegate(JiwaFinancials.Jiwa.JiwaInventory.Inventory inventory, string value, string rowData, string[] row, int rowNo, JiwaFinancials.Jiwa.JiwaInventory.Import.Mapping
mapping)
    {
        inventory.RRPPrice = decimal.Parse(value.Replace("$", ""));
    };
}

Re: Import Pre-processor  Topic is solved

PostPosted: Wed Mar 30, 2022 6:25 pm
by Mike.Sheen
I just realised ReadEnd is too late to add that handler - So you need to override the SetterMethod as shown in both the ReadEnd handler AND the setup method. Either copy the code into Setup, or refactor it into a method called by both Setup and ReadEnd handler.

Re: Import Pre-processor

PostPosted: Wed Mar 30, 2022 6:44 pm
by SBarnes
Thanks Mike,

Actually I think if memory serves correct you could do it in the readend but you have to remove the original handler/property, I did something similar to status for inventory so that if you changed the status to discontinued it would go off and clear out back orders and close purchase orders so the status change doesn't throw an exception, I'll start there.

By the way this same client discovered you can't have double quotes in the data such as product x with diameter 2" apparently excel will escape a double quote by turning it into "" when you convert to csv but Jiwa doesn't like that at all and of course ends up with its fields out of alignment and producing weird and wonderful errors that are then hard to diagnose.