Update Main form from Subform

sendohsendoh Member Posts: 207
hi all,

I want to know is it possible to update the main form from subform please tell me how..

thnx...
Sendoh
be smart before being a clever.

Comments

  • BeliasBelias Member Posts: 2,998
    you want only to do a "form.update" or change values in the header and save them?
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • kinekine Member Posts: 12,562
    If you will search this forum, you will find out that there are ways how to do that... simulating keys (through SendKey), timer etc...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • JAYESHJAYESH Member Posts: 290
    Hi..

    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.
    JAYESH PATEL
  • FordewindFordewind Member Posts: 27
    JAYESH wrote:
    Hi..

    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.
    Nav 4.0 sp3
  • sendohsendoh Member Posts: 207
    I actually update the main form from the subform, but I have to click the main form before it update. please give me some hints.... :-k
    Sendoh
    be smart before being a clever.
  • EugeneEugene Member Posts: 309
    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
  • sendohsendoh Member Posts: 207
    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.
    Sendoh
    be smart before being a clever.
  • FordewindFordewind Member Posts: 27
    sendoh!
    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]
    Nav 4.0 sp3
  • EugeneEugene Member Posts: 309
    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)
  • ajhvdbajhvdb Member Posts: 672
    does ctrl-alt-f5 update the main and subform?
  • themavethemave Member Posts: 1,058
    sendoh wrote:
    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.
  • sendohsendoh Member Posts: 207
    Thanks for the reply guys...I Follow what Vilnius said

    my solution to this is not showing the total amount until the entering of the lines is finished. :D
    Sendoh
    be smart before being a clever.
  • garakgarak Member Posts: 3,263
    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=;
    }
    PROPERTIES
    {
    Width=8000;
    Height=4840;
    OnOpenForm=BEGIN
    CREATE(XmlDoc);
    CurrForm.SubForm.FORM.SetXmlDoc(XmlDoc);
    END;
    
    OnCloseForm=BEGIN
    CLEAR(XmlDoc);
    END;
    
    }
    CONTROLS
    {
    { 1000000000;TextBox;330 ;220 ;4290 ;440 ;Editable=No;
    SourceExpr=TextVar }
    { 1000000001;SubForm;220 ;880 ;7480 ;2310 ;Name=SubForm;
    SubFormID=Form50001 }
    }
    CODE
    {
    VAR
    TextVar@1000000000 : Text[50];
    XmlDoc@1000000001 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{88D969C0-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v4.0'.DOMDocument40" WITHEVENTS;
    
    EVENT XmlDoc@1000000001::ondataavailable@198();
    BEGIN
    END;
    
    EVENT XmlDoc@1000000001::onreadystatechange@-609();
    BEGIN
    IF (XmlDoc.readyState = 4) THEN BEGIN
    TextVar := CurrForm.SubForm.FORM.GetText();
    CurrForm.UPDATE(FALSE);
    END;
    END;
    
    BEGIN
    END.
    }
    }
    
    OBJECT Form 50001 Child
    {
    OBJECT-PROPERTIES
    {
    Date=07-08-30;
    Time=15:19:54;
    Modified=Yes;
    Version List=;
    }
    PROPERTIES
    {
    Width=8030;
    Height=2420;
    }
    CONTROLS
    {
    { 1000000000;TextBox;220 ;220 ;4180 ;440 ;SourceExpr=TextVar1;
    OnAfterValidate=BEGIN
    SendMessage();
    END;
    }
    { 1000000001;TextBox;220 ;770 ;4180 ;440 ;SourceExpr=TextVar2 }
    }
    CODE
    {
    VAR
    TextVar1@1000000000 : Text[50];
    TextVar2@1000000002 : Text[50];
    XmlDoc@1000000001 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{88D969C0-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v4.0'.DOMDocument40";
    
    PROCEDURE SetXmlDoc@1000000000(pXmlDoc@1000000000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{88D969C0-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v4.0'.DOMDocument40");
    BEGIN
    XmlDoc := pXmlDoc;
    END;
    
    PROCEDURE SendMessage@1000000004();
    BEGIN
    XmlDoc.loadXML('<root></root>');
    END;
    
    PROCEDURE GetText@1000000001() : Text[50];
    BEGIN
    EXIT(TextVar1);
    END;
    
    BEGIN
    END.
    }
    }
    
    Regards
    Do you make it right, it works too!
  • FordewindFordewind Member Posts: 27
    garak,

    WOW! It's a perfect method!
    Especial respect from me!

    Du bist ein Meister in Nav! :-({|=
    Nav 4.0 sp3
  • sendohsendoh Member Posts: 207
    I agreed to fordewind its awesome.... =D> =D> =D> =D> =D>
    Sendoh
    be smart before being a clever.
  • ebsoftebsoft Member Posts: 81
    garak wrote:
    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
  • bob_upbob_up Member Posts: 155
    I had a similar requirement (hence finding your topic). I keep a running total and display this at the bottom of the subform, below the lines.

    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.
  • southindiansouthindian Member Posts: 247
    Can u explain me sir why we are using Automation for linking both the form
  • kinekine Member Posts: 12,562
    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... ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • croeselcroesel Member Posts: 1
    Anyone got the solution of sendoh working on RTC? I have tried but the event does not fire :-k
  • pdjpdj Member Posts: 643
    garak wrote:
    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?
    Regards
    Peter
  • serdarulutasserdarulutas Member Posts: 50
    Hi, here is an alternative solution if you are able to register an extra DLL component on client side: https://github.com/serdarulutas/NAVAutomation .
  • Van_ScimanydVan_Scimanyd Member Posts: 8
    edited 2015-12-10
    Since NAV 2013 R2 you can use Client Control Add-in to set up a javascript timer that triggers a NAV C/AL client side function on a page.

    https://msdn.microsoft.com/en-us/library/dn182584(v=nav.71).aspx

    Example :
    Javacscript :
    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.
  • cafeinecafeine Member Posts: 11
    That solution is awesome! Main form is updated instantly and no Times used! Thanks!
    garak wrote: »
    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=;
    }
    PROPERTIES
    {
    Width=8000;
    Height=4840;
    OnOpenForm=BEGIN
    CREATE(XmlDoc);
    CurrForm.SubForm.FORM.SetXmlDoc(XmlDoc);
    END;
    
    OnCloseForm=BEGIN
    CLEAR(XmlDoc);
    END;
    
    }
    CONTROLS
    {
    { 1000000000;TextBox;330 ;220 ;4290 ;440 ;Editable=No;
    SourceExpr=TextVar }
    { 1000000001;SubForm;220 ;880 ;7480 ;2310 ;Name=SubForm;
    SubFormID=Form50001 }
    }
    CODE
    {
    VAR
    TextVar@1000000000 : Text[50];
    XmlDoc@1000000001 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{88D969C0-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v4.0'.DOMDocument40" WITHEVENTS;
    
    EVENT XmlDoc@1000000001::ondataavailable@198();
    BEGIN
    END;
    
    EVENT XmlDoc@1000000001::onreadystatechange@-609();
    BEGIN
    IF (XmlDoc.readyState = 4) THEN BEGIN
    TextVar := CurrForm.SubForm.FORM.GetText();
    CurrForm.UPDATE(FALSE);
    END;
    END;
    
    BEGIN
    END.
    }
    }
    
    OBJECT Form 50001 Child
    {
    OBJECT-PROPERTIES
    {
    Date=07-08-30;
    Time=15:19:54;
    Modified=Yes;
    Version List=;
    }
    PROPERTIES
    {
    Width=8030;
    Height=2420;
    }
    CONTROLS
    {
    { 1000000000;TextBox;220 ;220 ;4180 ;440 ;SourceExpr=TextVar1;
    OnAfterValidate=BEGIN
    SendMessage();
    END;
    }
    { 1000000001;TextBox;220 ;770 ;4180 ;440 ;SourceExpr=TextVar2 }
    }
    CODE
    {
    VAR
    TextVar1@1000000000 : Text[50];
    TextVar2@1000000002 : Text[50];
    XmlDoc@1000000001 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{88D969C0-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v4.0'.DOMDocument40";
    
    PROCEDURE SetXmlDoc@1000000000(pXmlDoc@1000000000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{88D969C0-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v4.0'.DOMDocument40");
    BEGIN
    XmlDoc := pXmlDoc;
    END;
    
    PROCEDURE SendMessage@1000000004();
    BEGIN
    XmlDoc.loadXML('<root></root>');
    END;
    
    PROCEDURE GetText@1000000001() : Text[50];
    BEGIN
    EXIT(TextVar1);
    END;
    
    BEGIN
    END.
    }
    }
    
    Regards

  • JuhlJuhl Member Posts: 724
    Check out Nav 2017 Sales Order
    Follow me on my blog juhl.blog
Sign In or Register to comment.