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.
0
Comments
http://www.mibuso.com/forum/viewtopic.php?f=5&t=34199
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
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.
My Blog - nav.education
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 ...".
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.
What has that thread got to do with SubForms :-k
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).
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
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 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.
My Blog - nav.education
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
Gotcha.