Options

not editable subform is automatically disabled

Minu63Minu63 Member Posts: 16
To prevent some important data from unwanted modifications, we integrated a so-called "Modification Button" in several forms, so as in form 42 "Sales Order". There is following code behind this button:
CurrForm.EDITABLE(NOT CurrForm.EDITABLE);
CurrForm.SalesLines.FORM.SetFormEditable(CurrForm.EDITABLE);

In the subform 46 "Sales Order Subform" the new function "SetFormEditable" looks as follows:
CurrForm.EDITABLE(_Editable);
CurrForm.UPDATE;

This works more or less fine, but has one big problem: If there aren't any records to show in the subform, the subform is not only set to "not editable" but also automatically set to "not enabled"! And the status of the subform remains "not enabled" even if you change to status of the main form to "editable".

I attempted several combinations of CurrForm.ACTIVATE, CurrForm.ENABLE, etc. but the only workaround that ran was inserting an empty sales line, change the subform to "editable" and than deleting the just created sales line. Has anyone a better solution? Thanks in advance.

Comments

  • Options
    BeliasBelias Member Posts: 2,998
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Options
    matttraxmatttrax Member Posts: 2,309
    I'm pretty sure you don't need the editable function on the subform at all. The editable property on the parent form should be inherited by the subform.

    And, very unrelated, but you should technically be doing CurrForm.EDITABLE := YourValue instead of CurrForm.EDITABLE(YourValue). I know it's the same thing, but the first is the proper syntax.
  • Options
    Minu63Minu63 Member Posts: 16
    matttrax wrote:
    I'm pretty sure you don't need the editable function on the subform at all. The editable property on the parent form should be inherited by the subform.
    I'm sorry but you aren't right: you need the editable function on the subform if you want to avoid another inexplicable behavior of Navision: Although the editable property is inherited to the subform you still can delete records from the subform! Try it out...
    matttrax wrote:
    And, very unrelated, but you should technically be doing CurrForm.EDITABLE := YourValue instead of CurrForm.EDITABLE(YourValue). I know it's the same thing, but the first is the proper syntax.
    I know that both syntaxes exist and that's the same but my one seems more "elegant" to me. I also prefer p.e. "IF boolean THEN ..." instead of "IF boolean = TRUE THEN ...".
  • Options
    David_SingletonDavid_Singleton Member Posts: 5,479
    Minu63 wrote:
    To prevent some important data from unwanted modifications, we integrated a so-called "Modification Button" in several forms, so as in form 42 "Sales Order". There is following code behind this button:
    CurrForm.EDITABLE(NOT CurrForm.EDITABLE);
    CurrForm.SalesLines.FORM.SetFormEditable(CurrForm.EDITABLE);

    In the subform 46 "Sales Order Subform" the new function "SetFormEditable" looks as follows:
    CurrForm.EDITABLE(_Editable);
    CurrForm.UPDATE;

    This works more or less fine, but has one big problem: If there aren't any records to show in the subform, the subform is not only set to "not editable" but also automatically set to "not enabled"! And the status of the subform remains "not enabled" even if you change to status of the main form to "editable".

    I attempted several combinations of CurrForm.ACTIVATE, CurrForm.ENABLE, etc. but the only workaround that ran was inserting an empty sales line, change the subform to "editable" and than deleting the just created sales line. Has anyone a better solution? Thanks in advance.

    Personally I think this is a bug, but its been like that since the first release of Financials. I have reported this to PC&C (over 10 years ago) but never got a reply. Actually I reported a lot of bugs in SubForms, but most of them are still there.
    David Singleton
  • Options
    David_SingletonDavid_Singleton Member Posts: 5,479
    Belias wrote:

    What has that thread got to do with SubForms :-k
    David Singleton
  • Options
    Minu63Minu63 Member Posts: 16
    Belias wrote:
    Dear Belias
    I tried it out but I think you have the same problem as I: if you filter p.e. the currency code to "XYZ" your buttons are disabled too and don't work any longer (with or without the codeunit).
  • Options
    matttraxmatttrax Member Posts: 2,309
    Minu63 wrote:
    I'm sorry but you aren't right: you need the editable function on the subform if you want to avoid another inexplicable behavior of Navision: Although the editable property is inherited to the subform you still can delete records from the subform! Try it out...

    So it is correct, it's just that you have another problem with the way it works. I would agree that when it inherits the property you should not be able to delete records. I was about to suggest
    IF NOT CurrForm.EDITABLE THEN
      ERROR('You cannot delete records from an uneditable form')
    

    in the OnDelete trigger of your subform. I tried it out and although the property is inherited CurrForm.EDITABLE still returns TRUE. I can see your frustration :lol: What an annoying problem. I'm really surprised I've never run into it before.

    A real hack of a solution here, but it should work. It's far from elegant and I would definitely put some text in the documentation trigger explaining it. Have the editable property inherit from the parent form. But also have your function that, instead of setting the EDITABLE property, sets a global variable. Use that global variable as a conditional in your OnDelete trigger like in the snippet above. You still get the confirmation of "Do you want to delete the record?", unfortunately, but it will prevent you from deleting it.
  • Options
    BeliasBelias Member Posts: 2,998
    Belias wrote:

    What has that thread got to do with SubForms :-k
    i posted the link before the whole discussion of subform bug: it should have solved the issue about the empty table (which was one of the original problems)
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Options
    David_SingletonDavid_Singleton Member Posts: 5,479
    Belias wrote:
    [
    i posted the link before the whole discussion of subform bug: it should have solved the issue about the empty table (which was one of the original problems)

    Gotcha. :wink:
    David Singleton
Sign In or Register to comment.