Thursday, September 05, 2013

Refresh from after calling method

Refreshing a Form with a Single Root Data Source

To refresh a parent form, you can often use a task to refresh the form. You should use a task when the form has a single root data source. For example, the CustTableListPage, SalesTable, VendTable, and HcmWorker forms all have a single root data source. When you use a task to refresh the form, you cause a call to the research method for all data source tables associated with the form.
To update the form root data source

In the AOT, expand Forms, find the dialog or drop dialog form that you want to work with. Expand the form node.
Right-click the Methods node, click Override method, and then click closeOK. The method opens in the code editor.

Use the FormRun class together with the #taskF5 refresh task to refresh any form that opens this dialog or drop dialog form.
The following code example shows how to get a reference to the calling form and how to refresh that form. Notice how the formRun instance is populated with a reference to the calling form. Also notice how #taskF5 is used to force a refresh of the specified form.
X++
public void closeOk()
{
#Task
FormRun formRun;

super();

// Get an instance of the calling form.
formRun = element.args().caller();

// If the caller is a form, refresh that form.
if(formRun)
{
formRun.task(#taskF5);
}
}


In the code editor, press the compile button. When compiling is finished, close the code editor.

Right-click the form and then click Save.

To refresh the parent form, open the form you use to call the dialog or drop dialog form where you added the previous code. Select a record, open the dialog form, and make a change to a field that appears on the parent form. Click OK to close the dialog form. The parent form is refreshed and shows the value that you updated in the dialog form.
Refreshing a Form with Multiple Root Data Sources

The form that opens your dialog or drop dialog form might have multiple root data sources. For example, the smmActivities form has two root data sources. If you have more than one root data source, you should refresh the data source that includes fields that were updated by using the dialog or drop dialog form.
To find and update a specified root data source

In the AOT, find the dialog or drop dialog form that you want to work with. Expand the form node.
Right-click Methods, click Override method, and then click closeOK. The method opens in the code editor.
Use the FormRun class to get a reference to the calling form. You then have to iterate the list of root data sources to find the data source table that include the fields you updated in the dialog or drop dialog form. You must know the name of the root data source table.
The following code example shows how to get a reference to the calling form, how to iterate a list of root data sources, and how to use the research method to refresh a specified data source. Notice how the tableNum function specifies the root data source table you want to refresh. Caution
In the example, the target root data source table is named Table1. You would have to change this parameter to the name of the root data source table that contains the fields updated by the dialog or drop dialog form.

X++
public void closeOk()
{
FormRun formRun;
List dsList;
ListEnumerator dsListEnumerator;
FormDataSource formDS;

super();

// Get an instance of the calling form.
formRun = element.args().caller();

// If the caller is a form, find and refresh the specified root data source.
if(formRun)
{
dsList = formRun.rootFormDataSources();

if(dsList && dsList.elements() > 0)
{
dsListEnumerator = dsList.getEnumerator();

while(dsListEnumerator.moveNext())
{
formDS = dsListEnumerator.current();
if(formDS.table() == tableNum(Table1))
{
formDS.research(true);
break;
}
}
}
}
}

In the code editor, press the compile button. When compiling is finished, close the code editor.
Right-click the form and then click Save.
To refresh the parent form, open the form you use to call the dialog or drop dialog form where you added the previous code. Select a record, open the dialog form, and make a change to a field that appears on the parent form. Click OK to close the dialog form. The parent form is refreshed and shows the value that you updated in the dialog form.

sumber : http://msdn.microsoft.com/en-us/library/hh812104.aspx
READ MORE - Refresh from after calling method