Page 1 of 1

Copying a Sales Order (Sales Order Line - Custom Fields)

PostPosted: Wed Oct 28, 2015 3:28 pm
by marcosomizu
Hi,

I need help with the Sales Order Lines Custom Fields.

The problem is that when I copy a Sales Order that has all the informations (including the Custom Fields from the Sales Order Line), the new Sales Order looks just fine, but when I save it, it loses all the Custom Fields from the Sales Order Line.

Example:

1) Search for a Sales Order that has all the Custom Fields from the Sales Order Line(s) filled.
2) Copy this Sales Order
3) A new Sales Order will appear with all the information filled (so far it is working fine)
4) Save the Sales Order - automatically loses the Custom Fields from the Sales Order Line(s)

Can someone help me on this? I tried to force setting all the Custom Fields values when saving, but it still does not work.

What I tried:

Code: Select all
Public Sub SalesOrder_SaveStart(sender As Object, e As System.EventArgs)
      Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = DirectCast(sender, JiwaSales.SalesOrder.SalesOrder)
      Dim salesOrderForm As JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm = DirectCast(salesOrder.GenericObjectCollection("SalesOrderForm").Object, JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm)
      
      Dim gridSheet As JiwaFinancials.Jiwa.JiwaApplication.Controls.Sheet = DirectCast(salesOrderForm.grdLines.ActiveSheet, JiwaFinancials.Jiwa.JiwaApplication.Controls.Sheet)
      
      For row As Integer = 0 To gridSheet.Rows.Count - 1
         
         If Not IsNothing(gridSheet.GetValue(row, 0)) Then
            
            For Each line As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrderLine In salesOrder.SalesOrderLines
               
               If gridSheet.GetValue(row, 0).ToString() = line.RecID Then
                  
                  For Each customFieldValue As JiwaFinancials.Jiwa.JiwaApplication.CustomFields.CustomFieldValue In line.CustomFieldValues
                     
                     Select Case customFieldValue.CustomField.PluginCustomField.Name
                        
                     Case "PickPack"
                        line.CustomFieldValues.ItemFromSettingName("PickPack", "Plugin Name").Contents = gridSheet.Cells(row, gridSheet.Columns("Plugin Name.PickPack").Index).Text


Re: Copying a Sales Order (Sales Order Line - Custom Fields)

PostPosted: Fri Oct 30, 2015 9:24 am
by Scott.Pearce
The native copy only copies basic properties. The problem we often find is that some sites want some properties copied, and other sites do *not* want those same properties copied. A classic example of this is notes - should notes be copied across? Some say yes, others say no - it all depends on how a site uses the notes (for example, courier information for a specific sales order may be entered as a note which would not be relevant for the copy). To this end, we tend to use plugins to "fill in the gaps", so to speak, and I see that you are now attempting to do exactly that now for your site.

I'll dig up a plugin you can use and post it here shortly.

Re: Copying a Sales Order (Sales Order Line - Custom Fields)  Topic is solved

PostPosted: Fri Oct 30, 2015 9:43 am
by Scott.Pearce
I've posted up a sample plugin which should suit your needs here:

viewtopic.php?f=27&t=445

Re: Copying a Sales Order (Sales Order Line - Custom Fields)

PostPosted: Mon Nov 02, 2015 2:04 pm
by marcosomizu
Thank you Scott.

Just a suggestion: since it is debatable whether custom fields should be copied along or not, wouldn't it be better if it was a property/method to set in a Sales Order object, instead of creating new plugins in order to do this?

Something simple, for example: SalesOrder.CopyCustomFields = true

Anyway, is just an idea. Thank you for the plugin.