subform should know nothing about main form and it should be up to main form to manage itself. Try to rwrite your code in such a way that you do not need to update main form from subform. Most likely you will need to move some code from subform to main form
my solution to this is not showing the total amount until the entering of the lines is finished. Once it is finished (a conformation on the header form that changes the state of the whole document from open to confirmed and blocks further data entering in the lines) the total amount is calculated once.
You do not really want to degrade system efficiency by constantly recalculating total amount.
I mean you can do it your way but is it a good design decision ?
Navision uses separate Statistics tab-page on the forms to avoid constant re-calculation.
I see two problems with calculate-on-change design:
1) your subform maybe used from several different main forms so you would need to inform every type of main form
2) the underlying lines the subform shows can be simultaniously updated from different places (e.g. by other client)
thanks for the advice eugene,but this is the quick view..
in my subform there are the lines of amount
25.00
300.00
500.00
and I have to show the total of line amount...
825.00
this is the quick view for the user to see the total amount of their P.O.
You just need to see the total right, then add a field to the PO line table, make it a flow field based on the amount. then put this field bottom of your subform so it shows the total.
when you need to update an Main Form from an Subform you can't do this with standard navision functions like Mainform.update. Ok you can use an Timer or an single insta. Codeunit, but this is an :-( solution. But why not using XMLDom -> M$ maked it possible ;-)
when you need to update an Main Form from an Subform you can't do this with standard navision functions like Mainform.update. Ok you can use an Timer or an single insta. Codeunit, but this is an :-( solution. But why not using XMLDom -> M$ maked it possible ;-)
OBJECT Form 50000 Parent
{
OBJECT-PROPERTIES
{
Date=07-08-30;
Time=15:14:11;
Modified=Yes;
Version List=;
}...........
Regards
Perfect... but there's still a problem..
I can't use SendMessage() Function in OnAfterGetRecord of the subform.
It causes a runtime error, telling that object is not instanced!
How can I resolve this problem, avoiding a stupid timer?
I need that header updated everytime the user change from a line to another one.
Can u help me?
Many thanks.
Regards,
Federico
MBS Specialist since NAV 2.0
My experiences on Linkedin
I also added a function to the subform which initialises TotalLineAmount to the sum of the lines for the current mainform record. I called this from the OnAfterGetCurrRecord on the mainform.
All depends on where you are passing the automation from main form to the subform. May be that your trigger in the subform is called before the automation is passed from main to sub. Just add some flag variable which will tell you that the automation is already set and check it before you use the variable. That's all. The time line is critical in this... ;-)
But why not using XMLDom -> M$ maked it possible ;-)
This is a great solution we have used several placed. =D>
However; we are unable to use it in document forms, when the column also is the last field in the tab-order.
I.e. we have a field on the header we would like to have updated when the Qty is entered in a Sales Order, but we would also like the focus go to the No. field on a new line. This is normally done by setting NextControl to a control placed before the current control. But due to the CurrForm.UPDATE(FALSE) on the main-form, then it jumps to the first line in the sub-form, instead of a new line.
Our quick and dirty solution was to include a field to the right of Qty in the tab-order. Then it works like a charm, but the user has to jump through one field more than he wish.
Not a big problem - just wondering if anyone solved this detail?
function Refresh(){
Microsoft.Dynamics.NAV.InvokeExtensibilityMethod('Refresh', null);
}
function Activate(interval){ // interval in ms
window.setInterval(Refresh, interval);
}
C/AL :
Refresher::ControlAddInReady()
CurrPage.Refresher.Activate(100);
Refresher::Refresh()
IF SubPageHasChanged THEN
UpdateAnOtherSubPage();
IF TimeHasCome THEN
DoWhatNeedsToBeDone();
Of course this is very hacky, but it defenitely works, and AFAIK it's the only solution which works if one wants to trigger client side component like CurrPage.UPDATE or any function that needs to be running client-side.
Plus it can be useful if you want to trigger something at a given time (like an OnAfterOpen() function).
The main advantage compared to a classic Controll Add-In is that the DLL needs to be put only one time in the server Add-In directory, after that it will copy automatically on any client, including Web and Tablet.
The main drawback is that the controll add-in field must be visible and it takes up place, you can always put it out of a group at the end but there will be a short blank at the bottom. Maybe playing around with the css of the html generated by Microsoft could reduce it.
when you need to update an Main Form from an Subform you can't do this with standard navision functions like Mainform.update. Ok you can use an Timer or an single insta. Codeunit, but this is an :-( solution. But why not using XMLDom -> M$ maked it possible ;-)
Comments
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
By FORM.UPDATE you can update the Header form.
For Subform Give the name to the Subform.
ON OnValidate() trigger
CurrForm.SAVERECORD;
CurrForm.Name of Subform.FORM.Update();
And in the Subform create Function called Update()
and write code.
CurrForm.UPDATE(FALSE);
By written this you can update Subform.
Your scenario will update Subform from Form, but not Form from Subform.
be smart before being a clever.
in my subform there are the lines of amount
25.00
300.00
500.00
and I have to show the total of line amount...
825.00
this is the quick view for the user to see the total amount of their P.O.
be smart before being a clever.
Read kine replay!
Set up timer on main form and update it from time to time. Or you may show total in subform.
Search ruleazzz [/b]
You do not really want to degrade system efficiency by constantly recalculating total amount.
I mean you can do it your way but is it a good design decision ?
Navision uses separate Statistics tab-page on the forms to avoid constant re-calculation.
I see two problems with calculate-on-change design:
1) your subform maybe used from several different main forms so you would need to inform every type of main form
2) the underlying lines the subform shows can be simultaniously updated from different places (e.g. by other client)
my solution to this is not showing the total amount until the entering of the lines is finished.
be smart before being a clever.
Regards
WOW! It's a perfect method!
Especial respect from me!
Du bist ein Meister in Nav! :-({|=
be smart before being a clever.
Perfect... but there's still a problem..
I can't use SendMessage() Function in OnAfterGetRecord of the subform.
It causes a runtime error, telling that object is not instanced!
How can I resolve this problem, avoiding a stupid timer?
I need that header updated everytime the user change from a line to another one.
Can u help me?
Many thanks.
Federico
MBS Specialist since NAV 2.0
My experiences on Linkedin
I added the following code to the subform :
OnInsertRecord
TotalLineAmount += Amount;
OnModifyRecord
TotalLineAmount += Amount-xRec.Amount;
OnDeleteRecord
TotalLineAmount - Amount;
I also added a function to the subform which initialises TotalLineAmount to the sum of the lines for the current mainform record. I called this from the OnAfterGetCurrRecord on the mainform.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
However; we are unable to use it in document forms, when the column also is the last field in the tab-order.
I.e. we have a field on the header we would like to have updated when the Qty is entered in a Sales Order, but we would also like the focus go to the No. field on a new line. This is normally done by setting NextControl to a control placed before the current control. But due to the CurrForm.UPDATE(FALSE) on the main-form, then it jumps to the first line in the sub-form, instead of a new line.
Our quick and dirty solution was to include a field to the right of Qty in the tab-order. Then it works like a charm, but the user has to jump through one field more than he wish.
Not a big problem - just wondering if anyone solved this detail?
Peter
https://msdn.microsoft.com/en-us/library/dn182584(v=nav.71).aspx
Example :
Javacscript :
C/AL :
Of course this is very hacky, but it defenitely works, and AFAIK it's the only solution which works if one wants to trigger client side component like CurrPage.UPDATE or any function that needs to be running client-side.
Plus it can be useful if you want to trigger something at a given time (like an OnAfterOpen() function).
The main advantage compared to a classic Controll Add-In is that the DLL needs to be put only one time in the server Add-In directory, after that it will copy automatically on any client, including Web and Tablet.
The main drawback is that the controll add-in field must be visible and it takes up place, you can always put it out of a group at the end but there will be a short blank at the bottom. Maybe playing around with the css of the html generated by Microsoft could reduce it.