Page 1 of 1

CarrierChange Breakout doesnt sent sales order object

PostPosted: Fri Aug 18, 2023 9:49 am
by Ernst
See image when doing a change to Carrier, I'd like to do some logic. But the salesorderhistory.CarrierChanged
breakout supplies HistoryNo, and FieldName, which means I cannot access the rest of the sales order object to check things. Do I have to do some fancy workaround, or is there a way to access the salesorder object, even though its not passed in parameters.

Untitled.jpg
Untitled.jpg (33.63 KiB) Viewed 2164 times

Re: CarrierChange Breakout doesnt sent sales order object  Topic is solved

PostPosted: Fri Aug 18, 2023 10:57 am
by Mike.Sheen
Use a lambda function as the event handler to access whatever is in scope.

Code: Select all
Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
   If TypeOf JiwaForm Is JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm Then
      Dim salesOrderForm As JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm = DirectCast(JiwaForm, JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm)
      
      AddHandler salesOrderForm.SalesOrder.SalesOrderHistorys.CarrierChanged,
         Function(ByVal HistoryNo As Short, ByVal FieldName As String)             
            SalesOrderHistorys_CarrierChanged(HistoryNo, FieldName, salesOrderForm.SalesOrder)
         End Function
   End If
End Sub

Private Sub SalesOrderHistorys_CarrierChanged(ByVal HistoryNo As Short, ByVal FieldName As String, SalesOrder As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder)
   ' Now in here you have access to the sales order
End Sub

Re: CarrierChange Breakout doesnt sent sales order object

PostPosted: Mon Aug 21, 2023 2:08 pm
by Ernst
Very Clever, Never knew you could do that.. Thanks Mike.

Re: CarrierChange Breakout doesnt sent sales order object

PostPosted: Mon Aug 21, 2023 6:41 pm
by SBarnes
You can also do it in c# as well the plugin I gave you here viewtopic.php?f=26&t=2314 is doing a similar thing its just not adding parameters and calling to a separate method for example


Code: Select all
JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm sform = (JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm )JiwaForm;
         JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder salesorder = sform.SalesOrder;
         salesorder.SalesOrderLineAdded += delegate(object sender, EventArgs e, SalesOrderLine item)
         {
sform.grdCartage.LockRow(1,true);
sform.grdCartage.LockRow(2,true);
         };


could have been


Code: Select all
JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm sform = (JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm )JiwaForm;
         JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder salesorder = sform.SalesOrder;
         salesorder.SalesOrderLineAdded += delegate(object sender, EventArgs e, SalesOrderLine item)
         {
            LockGrid(sform );
         };

private void LockGrid(JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm sform)
{
    sform.grdCartage.LockRow(1,true);
    sform.grdCartage.LockRow(2,true);
}


Re: CarrierChange Breakout doesnt sent sales order object

PostPosted: Mon Aug 21, 2023 7:18 pm
by Mike.Sheen
Don't get carried away, Stuart - we can't expect people to understand what they get given and be able to apply that to different situations. That would be learning.

A drawback of the lambda function technique (whether it be VB or C#) is that the handler cannot be removed, as I pointed out in this post. Usually not a problem, but worth knowing as one day you'll waste time trying to do exactly that.

Re: CarrierChange Breakout doesnt sent sales order object

PostPosted: Mon Aug 21, 2023 7:27 pm
by SBarnes
Mike.Sheen wrote:A drawback of the lambda function technique (whether it be VB or C#) is that the handler cannot be removed, as I pointed out in this post. Usually not a problem, but worth knowing as one day you'll waste time trying to do exactly that.


Yes I remember you posting that and yes I didn't know it before you did but have membered it since. :lol: