Header Ads Widget

How to Pass Parameters Between Forms in Dynamics 365 FO

 In Microsoft Dynamics 365 for Finance and Operations, there may be situations where you need to pass data between different forms. This can be accomplished by using the Args class, which facilitates parameter passing between forms.

Let’s walk through an example where we’ll create two forms—FormA and FormB—and pass a parameter from FormA to FormB.

Steps to Implement Parameter Passing:

1. Create Two Forms

  • FormA: This is where you will input the data you want to pass.

  • FormB: This is where you will receive the data.

2. Override the clicked() Method in FormA

In FormA, you will override the clicked() method of the button (or any action you want to trigger) to pass the parameter to FormB. Here’s how:

x++
void clicked() { Args args; FormRun formRun; args = new Args(); // Passing a simple string parameter args.parm(LeaveRequestID.text()); // For example, a string parameter // Passing a whole record (table data) args.record(TableName); // Run FormB and pass the arguments args.name(formstr(FormB)); // Name of the target form formRun = classFactory.formRunClass(args); formRun.init(); formRun.run(); formRun.wait(); super(); }
  • In the code above, the parm() method of the Args class is used to pass the value of a string (such as a leave request ID) from FormA.

  • We also pass an entire record (e.g., a TableName) using the record() method.

  • Finally, we initialize and run FormB using the arguments.

3. Override the init() Method in FormB

In FormB, you will need to override the init() method to receive and process the parameters passed from FormA. Here's an example of how to retrieve the string and record:

x++
public void init() { str passedStringValue; TableName passedTableRecord; super(); // Check if arguments were passed if (element.args()) { // Retrieve the string parameter passed from FormA passedStringValue = element.args().parm(); SelectedLeaveRequestID.text(passedStringValue); // Display the value on FormB // Retrieve the record parameter passed from FormA passedTableRecord = element.args().record(); // Now you can work with the passed record } }
  • In the init() method of FormB, we use the element.args() method to get the arguments passed from FormA.

  • The parm() method retrieves the string value (in this case, the leave request ID), and the record() method retrieves the entire record (e.g., a specific table record).

  • The retrieved values can then be used within FormB, such as displaying the leave request ID or working with the passed record data.

Conclusion

This simple example demonstrates how to pass parameters from one form to another in Dynamics 365 FO using the Args class. You can pass both simple data like strings and more complex data like entire records, making it easy to transfer information between forms in your applications.

Post a Comment

0 Comments