How to pass values between two event handlers?

2.4k views Asked by At

In my first event handler, I will collect all the fields I need from the SalesTable form. In this form, I need to get these fields from the SalesLine. Below is my code:

[FormEventHandler(formStr(SalesTable), FormEventType::PostRun)]
public static void SalesTable_OnPostRun(xFormRun sender, FormEventArgs e)
{
      SalesLine   salesLine;
      SalesTable  salesTable = sender.dataSource(formDataSourceStr(SalesTable,salesTable)).cursor();

      select ItemId, SalesId, ShippingDateConfirmed from salesLine
         where salesLine.SalesId == SalesTable.SalesId;
}

After that, this next event handler is the OnClick event of a button found in another form..

[FormControlEventHandler(formControlStr(SalesAvailableDlvDates, TransferToConfirmedButton), FormControlEventType::Clicked)]
public static void TransferToConfirmedButton_OnClicked(FormControl sender, FormControlEventArgs e)
{
    //some code here
}

In this event handler of a different form which is SalesAvailableDlvDates, here I need the fields from my SalesLine table which I obtained from the SalesTable form. Because in here, this is the button needed to be triggered where this will place values into a newly created table.

Is there anyway I can pass the values from the SalesTable event handler to the SalesAvailableDlvDates event handler?

Because in SalesAvailableDlvDates, I COULD NOT obtain the SalesLine data. Is it possible to pass values from one event handler to another?

1

There are 1 answers

5
Aliaksandr Maksimau On BEST ANSWER

In SalesAvailableDlvDates form event handler you can obtain the form caller. Then if salesCalcAvailableDlvDates is a SalesCalcAvailableDlvDates_SalesTable or SalesCalcAvailableDlvDates_SalesLine you can get data you needed from the corresponding parm method.

[FormControlEventHandler(formControlStr(SalesAvailableDlvDates, TransferToConfirmedButton), FormControlEventType::Clicked)]
public static void TransferToConfirmedButton_OnClicked(FormControl sender, FormControlEventArgs e)
{
    SalesTable                              salesTable;
    SalesLine                               salesLine;
    SalesCalcAvailableDlvDates              salesCalcAvailableDlvDates;
    SalesCalcAvailableDlvDates_SalesLine    salesCalcAvailableDlvDates_SalesLine;
    SalesCalcAvailableDlvDates_SalesTable   salesCalcAvailableDlvDates_SalesTable;
    FormRun                                 formRun;
    ;

    formRun = sender.formRun() as FormRun;
    salesCalcAvailableDlvDates = formRun.args().caller();

    switch (classIdGet(salesCalcAvailableDlvDates))
    {
        case classNum(SalesCalcAvailableDlvDates_SalesLine):
            salesCalcAvailableDlvDates_SalesLine = salesCalcAvailableDlvDates as SalesCalcAvailableDlvDates_SalesLine;
            salesLine = salesCalcAvailableDlvDates_SalesLine.parmSalesLine();
            salesTable = salesLine.salesTable();
            break;

        case classNum(SalesCalcAvailableDlvDates_SalesTable):
            salesCalcAvailableDlvDates_SalesTable = salesCalcAvailableDlvDates as salesCalcAvailableDlvDates_SalesTable;
            salesTable = salesCalcAvailableDlvDates_SalesTable.parmSalesTable();
            break;

        default:
            break;
    }
}