How to refresh a parent form while updating the child form in axapta 2009?

I was created two forms. One is the parent and another one is the child form. whenever i am adding the row or deleting the row in the child form, i want to update the calculation in the parent form field…

The problem is whenever adding the row or deleting the row from the child form, the parent form field is not updated.

I need to press F5 after that only it will update…

Please give the solution for this issue…

I am struggling this stage…

Thanks in advance…

hi,

i think you need to give this in the clicked() method of the button.

void clicked()
{

;

super();
tablename_ds.reread();
tablename_ds.refresh();
tablename_ds.research(true);
tablename_ds.research(true);

}

Thanks for your reply.

i tried this code already but it is not working…

Give some other solution for me…

Thanks…

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
&

Hi,

It is quite straight forward. In the parent form, write a method like below -

void bookrefresh()
{

.reread(); .refresh(); }

In the child form, you can do this -

void bookRefresh()
{
FormRun callerForm = element.args().caller();

if (callerForm)
{
if (callerForm.name() == formstr())
{
callerForm.bookRefresh();
}
}
}

Hello Friends,

Thanks for your valuable Response…

I got One more solution…

Solution:

After Writing or Deleting the record from the child form you just mention these lines…

write()

{

ParentTable_ds.reread();

element.args().record().reread();

}

The Parent Form will update correctly…

Act i m here not using datasource so how it will refresh and update the table…m using here element.args.record

plz reply

Hi,

Try to use this code on the current form…

public void close()

{

FormRun callerForm;

;

callerForm = element.args().caller();

callerForm.dataSource().refresh();

callerForm.dataSource().reread();

callerForm.dataSource().research();

super();

}

Thanks @Pranav the code actually worked, and does make logical connection.
I really appreciate it. :slight_smile: