m1gs
m1gs

Reputation: 197

How to refresh a form in dynamics ax7/365

I have two forms FormA (SalesTable) and FormB (SalesAvailableDlvDates).

From FormA, I will click a button to open up FormB.
Then I will click another button in FormB which will bring me back to FormA.

What I want to happen is, when I click the button in FormB I would like to refresh FormA as I get back to that form.

Is that possible?

This is the button in FormB where when I click it, I'll go back to FormA:

[FormControlEventHandler(formControlStr(SalesAvailableDlvDates, TransferToConfirmedButton), FormControlEventType::Clicked)]
    public static void TransferToConfirmedButton_OnClicked(FormControl sender, FormControlEventArgs e)

Upvotes: 0

Views: 8302

Answers (2)

vmoskalenko
vmoskalenko

Reputation: 46

In my example,

  • FormA is LogisticsPostalAddressGrid (or any other form).
  • FormB is LogisticsLocationDefault

On clicking on the OK button on the LogisticsLocationDefault (FormB) form, the data on the LogisticsPostalAddressGrid (FormA) will be refreshed.

Please find an example for the form LogisticsLocationDefault below.

/// <summary>
///     Valery Moskalenko, 12/20/2021
/// </summary>
class MyLogisticsLocationDefault_FormEventHandler
{
    /// <summary>  
    ///     Refresh caller form (LogisticsPostalAddressGrid) on clicking the OK button.
    /// </summary>
    /// <param name="_sender">FormControl</param>
    /// <param name="_e">FormControlEventArgs</param>
    [FormControlEventHandler(formControlStr(LogisticsLocationDefault, OK), FormControlEventType::Clicked),
     SuppressBPWarningAttribute('BPParameterNotUsed', 'This is expected and can be skipped')]
    public static void OK_OnClicked(FormControl _sender, FormControlEventArgs _e)
    {
        FormRun formRun = _sender.formRun();

        if (formRun)
        {
            FormRun callerFormRun = formRun.args().caller();

            if (callerFormRun)
            {
                #Task
                callerFormRun.task(#taskRefresh);
            }
        }
    }

}

Upvotes: 0

10p
10p

Reputation: 6706

You have FormControl sender - the form control raising the event.

Would the following work for you?

FormRun formRun = sender.formRun();      // get the caller form
FormObjectSet ds = formRun.dataSource(); // caller form's datasource
ds.reread();
ds.refresh();                            // refresh values in the caller form
//or ds.research(true);

Upvotes: 0

Related Questions