Thursday, April 29, 2010

Retrieving Control Values from an Existing Form Instantiated in X++

In one of my recent requirements, I needed to instantiate the smmEmailDistribution Form from a custom form that I had created, once control was returned to the custom form, then I needed to pull the values of various elements that the user had modified on the smmEmailDistribution form. How this is done was not immediately clear, and after spending hours attempting to find an example of this type of functionality in my reference books and via general googling, I eventually made a post on the Dynamics User Group forum. Oddly enough however, shortly after posting my question (less than an hour), I discovered the answer on my own by good old trial-and-error. The code below was placed in the clicked() method of a button on my custom Form, and does exactly what my need required:

void clicked()

FormStringControl strEdit;
Args args;
FormRun formRun;


args = new args();;
formRun = classFactory.formRunClass(Args);

// Get the Email1 control from smmEmailDistribution
strEdit ="Email1");