Copy Line Custom Field Data When Copying a Sales Order
Posted: Fri Oct 30, 2015 9:43 am
By default, sales order line custom field values are *not* brought across when copying a sales order (in fact, it looks like they are only shallow copied). This plugin changes the behaviour such that sales order line custom field values *do* come across to the copy, and are saved with the copy.
The plugin works by performing a deep copy on each lines' custom field value collection after a sales order copy has occurred. There is not much code to it, so I'll post it here in additional to the attached plugin XML:
The plugin works by performing a deep copy on each lines' custom field value collection after a sales order copy has occurred. There is not much code to it, so I'll post it here in additional to the attached plugin XML:
- Code: Select all
Public Class BusinessLogicPlugin
Inherits System.MarshalByRefObject
Implements JiwaApplication.IJiwaBusinessLogicPlugin
Public Overrides Function InitializeLifetimeService() As Object
' returning null here will prevent the lease manager
' from deleting the Object.
Return Nothing
End Function
Public Sub Setup(ByVal JiwaBusinessLogic As JiwaApplication.IJiwaBusinessLogic, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaBusinessLogicPlugin.Setup
If TypeOf JiwaBusinessLogic Is JiwaSales.SalesOrder.SalesOrder Then
Dim salesOrderObject As JiwaSales.SalesOrder.SalesOrder = DirectCast(JiwaBusinessLogic, JiwaSales.SalesOrder.SalesOrder)
AddHandler salesOrderObject.CopyEnd, AddressOf salesOrderObject_CopyEnd
End If
End Sub
Public Sub salesOrderObject_CopyEnd(sender As Object, e As System.EventArgs)
Dim salesOrderObject As JiwaSales.SalesOrder.SalesOrder = DirectCast(sender, JiwaSales.SalesOrder.SalesOrder)
For Each salesOrderLine As JiwaSales.SalesOrder.SalesOrderLine In salesOrderObject.SalesOrderLines
salesOrderLine.CustomFieldValues.Copy
Next
End Sub
End Class