you can try this material…go through the steps…given…and you have each example for that…
Exportfile for AOT version 1.0 or later
Formatversion: 1
***Element: CLS
; Microsoft Dynamics AX Class: Tutorial_FormDataSourceRefresh unloaded
; --------------------------------------------------------------------------------
CLSVERSION 1
CLASS #Tutorial_FormDataSourceRefresh
PROPERTIES
Name #Tutorial_FormDataSourceRefresh
Extends #RunBase
RunOn #Called from
ENDPROPERTIES
METHODS
Version: 3
SOURCE #classDeclaration
#///
#/// Class that will execute on the server, demonstrating processing of multiple rows and the use of RefreshEx() method
#///
#public class Tutorial_FormDataSourceRefresh extends RunBase
#{
Unit Unit;
#DEFINE.CurrentVersion(1)
#}
ENDSOURCE
SOURCE #pack
#public container pack()
#{
;
return [#CurrentVersion];
#}
ENDSOURCE
SOURCE #parmUnit
#public Unit parmUnit(Unit _Unit)
#{
;
if (!prmisdefault (_Unit))
{
Unit = _Unit;
}
return Unit;
#}
ENDSOURCE
SOURCE #run
#// The method should be executed on the server.
#public void run()
#{
FormDataSource formDataSource;
Unit iterateUnit;
Set setRecords = new Set(Types::Record);
SetEnumerator setEnumerator;
void toggleLockedForReschedule(Unit _Unit)
{
_Unit.selectForUpdate(true);
_unit.UnitDecimals = 4;
_Unit.doUpdate();
}
;
super();
formDataSource = Unit.dataSource();
if (formDataSource)
{
// iterate through the datasource, get the selected records
for (iterateUnit = formDataSource.getFirst(true) ? formDataSource.getFirst(true) : Unit;
iterateUnit; iterateUnit = formDataSource.getNext())
{
toggleLockedForReschedule(iterateUnit);
setRecords.add(iterateUnit);
}
// update the data in the grid
formDataSource.research(true);
// iterate through all the previously marked records and mark them again
// in order to preserve the marked records on the datasource
setEnumerator = setRecords.getEnumerator();
while (setEnumerator && setEnumerator.moveNext())
{
formDataSource.markRecord(setEnumerator.current(), 1);
}
formDataSource.refreshEx(-2);
}
#}
ENDSOURCE
SOURCE #unpack
#public boolean unpack(container packedClass)
#{
boolean ret;
Integer version = conpeek(packedClass,1);
switch (version)
{
default:
case(#CurrentVersion) :
ret = true;
break;
}
return ret;
#}
ENDSOURCE
SOURCE #construct
#public static server Tutorial_FormDataSourceRefresh construct(Args _args)
#{
Tutorial_FormDataSourceRefresh tutorial_FormDataSourceRefresh;
;
tutorial_FormDataSourceRefresh = new Tutorial_FormDataSourceRefresh();
tutorial_FormDataSourceRefresh.parmUnit(_args.record());
return tutorial_FormDataSourceRefresh;
#}
ENDSOURCE
SOURCE #main
#public static server void main(Args _args)
#{
Tutorial_FormDataSourceRefresh tutorial_FormDataSourceRefresh;
;
tutorial_FormDataSourceRefresh = Tutorial_FormDataSourceRefresh::construct(_args);
tutorial_FormDataSourceRefresh.run();
#}
ENDSOURCE
ENDMETHODS
ENDCLASS
***Element: FRM
; Microsoft Dynamics AX Forms unloaded
; --------------------------------------------------------------------------------
FRMVERSION 5
FORM #tutorial_FormDataSourceRefresh
PROPERTIES
Name #tutorial_FormDataSourceRefresh
ENDPROPERTIES
METHODS
Version: 3
SOURCE #classDeclaration
#public class FormRun extends ObjectRun
#{
#}
ENDSOURCE
SOURCE #instructionsText
#str instructionsText()
#{
str instructions;
;
instructions =
#@"Step 1.
#Update any of the fields on the selected row and click ‘Step 1. Refresh’ button.
#The button has SaveRecord property set to Yes, so the changes are automatically persisted, and thus you don’t see any changes to the record.
#Step 2.
#Update any of the fields on the selected row and click ‘Step 2. Reread’ button.
#This button has SaveRecord property set to Yes. so calling reread here just rereads the same data after saving, and thus you don’t see any changes.
#Step 3.
#Update any of the fields on the selected row and click ‘Step 3. Reread’ button.
#This button has SaveRecord property set to No. Therefore calling reread with reread the record from DB and erase any changes done to the current record.
#Refresh is not called, so you don’t see the revert at once. But if you navigate away from the record or press F5, you will see your changes reverted.
#Step 4.
#Update any of the fields on the selected row and click ‘Step 4. Reread and refresh’ button.
#SaveRecord = No on this button will ensure that Reread revents any changes. Refresh with update the form view, therefore this call is equivalent to a Ctrl+F5 Restore
#Step 5.
#Remember the unit description of the currently selected row. Click ‘Step 5. Reread and refresh’ button.
#The unit description for the current record will be updated from code.
#In order to actually show these changes on the form, we need to reread them from the DB and update the form view by calling refresh.
#Revert the unit description to the original value if necessary.
#Step 6.
#Multi-select 2 or more rows. Remeber the unit descriptions on these rows. Click ‘Step 6. RefreshEx’
#The selected records are updated from code, but we would like to preserve the multi-selection for the user.
#So after calling research() to update the data on the grid, we mark the records again, and call refreshEx to update the view on the form accordingly.
#Revert the unit descriptions to their original values if necessary.
#Step 7.
#Filter the rows displayed on unit description, specifying the following filter criteria: ‘Unit:*’. Set the cursor on the 2nd or 3rd record (not on the first).
#Click ‘Step 7. Research’ button. This will create 2 extra records with a similar unit description and call research to update the view.
#Note, that the cursor jumped back to the first row. The user filter you applied, however, was preserved.
#Step 8.
#Repeat the steps from Step 7, clicking on button ‘Step 8. Research’ instead.
#This time, the cursor will stay at the original position, because of calling research with an extra boolean argument.
#No new rows will be created as part of this step.
#Step 9.
#Repeat the steps from Step 7, clicking on button ‘Step 9. ExecuteQuery’ instead.
#The code will update the query, setting the filter on unit decimals instead of unit description, adding sorting on unit description.
#In order to display the data based on the new query, executeQuery is called.
#Note, that the query is refreshed, so the user filter applied on unit description is dropped.";
return instructions;
#}
ENDSOURCE
SOURCE #init
#public void init()
#{
super();
StringEditInstructions.text(this.instructionsText());
#}
ENDSOURCE
SOURCE #uniqueText
#str uniqueText()
#{
return strfmt(“Unit:%1”, timenow());
#}
ENDSOURCE
ENDMETHODS
OBJECTBANK
PROPERTIES
ENDPROPERTIES
DATASOURCE
OBJECTPOOL
PROPERTIES
Name #Unit
Table #Unit
InsertAtEnd #No
InsertIfEmpty #No
ENDPROPERTIES
FIELDLIST
ENDFIELDLIST
ENDOBJECTPOOL
ENDDATASOURCE
ENDOBJECTBANK
JOINS
ENDJOINS
DESIGN
PROPERTIES
Caption #Tutorial about form datasource methods: refresh(), reread(), research(), executeQuery()
ENDPROPERTIES
CONTAINER
CONTROL TAB
PROPERTIES
Name #Tab
Width #Column width
Tabs #1
ShowTabs #No
ENDPROPERTIES
CONTAINER
CONTROL TABPAGE
PROPERTIES
Name #TabPageData
Caption #Tutorial workspace
ENDPROPERTIES
CONTAINER
CONTROL GRID
PROPERTIES
Name #Grid
Width #Column width
DataSource #Unit
ENDPROPERTIES
CONTAINER
CONTROL STRINGEDIT
PROPERTIES
Name #Unit_UnitId
DataSource #Unit
DataField #UnitId
ENDPROPERTIES
ENDCONTROL
CONTROL STRINGEDIT
PROPERTIES
Name #Unit_Txt
DataSource #Unit
DataField #Txt
ENDPROPERTIES
ENDCONTROL
CONTROL INTEDIT
PROPERTIES
Name #Unit_UnitDecimals
DataSource #Unit
DataField #UnitDecimals
ENDPROPERTIES
ENDCONTROL
CONTROL COMBOBOX
PROPERTIES
Name #Unit_UnitSystem
DataSource #Unit
DataField #UnitSystem
ENDPROPERTIES
ENDCONTROL
ENDCONTAINER
ENDCONTROL
CONTROL BUTTONGROUP
PROPERTIES
Name #ButtonGroup
ENDPROPERTIES
CONTAINER
CONTROL BUTTON
PROPERTIES
Name #Step1_Refresh
Text #Step 1. Refresh
ENDPROPERTIES
METHODS
Version: 3
SOURCE #clicked
#void clicked()
#{
super();
Unit_ds.refresh();
#}
ENDSOURCE
ENDMETHODS
ENDCONTROL
&