Easy to implement Show/Modify Feature

BeliasBelias Member Posts: 2,998
edited 2009-05-11 in NAV Tips & Tricks
Hi everyone, sometimes customers ask for a Show/Modify button feature on some forms, and asks it on...let's say 20 forms.
Usually we create 2 buttons one above the other and then show the visibility and manage the editablity of the form.
Also they want the form to be "not editable" when opening it.
(See the example if you have never done it).
The "problem" is that if the form is empty and not editable, our buttons will be disabled and therefore the form is useless.
The simplest solution to this problem is to write some code in the onopenform in order to do an ISEMPTY test on the table.
And what about upgrades? It's not comfortable at all to move code and copy buttons and my laziness brought me to think to this workaround.
(see the example). In this way, the functionality will be available out of the box only copying and pasting the bottom left controls (2 command buttons and a textbox).
P.S.: you should create the codeunit (or a function somewhere), too

OBJECT Form 55555 TestForm
{
  OBJECT-PROPERTIES
  {
    Date=08/05/09;
    Time=17.14.57;
    Modified=Yes;
    Version List=;
  }
  PROPERTIES
  {
    Width=13550;
    Height=6710;
    TableBoxID=1101339000;
    SourceTable=Table4;
  }
  CONTROLS
  {
    { 1101339000;TableBox;220 ;220  ;13110;5500 ;HorzGlue=Both;
                                                 VertGlue=Both }
    { 1101339001;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1101339000;
                                                 InColumn=Yes;
                                                 SourceExpr=Code }
    { 1101339002;Label  ;0    ;0    ;0    ;0    ;ParentControl=1101339001;
                                                 InColumnHeading=Yes }
    { 1101339003;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1101339000;
                                                 InColumn=Yes;
                                                 SourceExpr="Last Date Modified" }
    { 1101339004;Label  ;0    ;0    ;0    ;0    ;ParentControl=1101339003;
                                                 InColumnHeading=Yes }
    { 1101339005;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1101339000;
                                                 InColumn=Yes;
                                                 SourceExpr="Last Date Adjusted" }
    { 1101339006;Label  ;0    ;0    ;0    ;0    ;ParentControl=1101339005;
                                                 InColumnHeading=Yes }
    { 1101339007;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1101339000;
                                                 InColumn=Yes;
                                                 SourceExpr="Unrealized Gains Acc." }
    { 1101339008;Label  ;0    ;0    ;0    ;0    ;ParentControl=1101339007;
                                                 InColumnHeading=Yes }
    { 1101339009;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1101339000;
                                                 InColumn=Yes;
                                                 SourceExpr="Realized Gains Acc." }
    { 1101339010;Label  ;0    ;0    ;0    ;0    ;ParentControl=1101339009;
                                                 InColumnHeading=Yes }
    { 1101339011;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1101339000;
                                                 InColumn=Yes;
                                                 SourceExpr="Unrealized Losses Acc." }
    { 1101339012;Label  ;0    ;0    ;0    ;0    ;ParentControl=1101339011;
                                                 InColumnHeading=Yes }
    { 1101339013;TextBox;0    ;0    ;1700 ;0    ;ParentControl=1101339000;
                                                 InColumn=Yes;
                                                 SourceExpr="Realized Losses Acc." }
    { 1101339014;Label  ;0    ;0    ;0    ;0    ;ParentControl=1101339013;
                                                 InColumnHeading=Yes }
    { 1101339015;CommandButton;6290;5940;2200;550;
                                                 HorzGlue=Right;
                                                 VertGlue=Bottom;
                                                 Default=Yes;
                                                 PushAction=LookupOK;
                                                 InvalidActionAppearance=Hide }
    { 1101339016;CommandButton;8710;5940;2200;550;
                                                 HorzGlue=Right;
                                                 VertGlue=Bottom;
                                                 Cancel=Yes;
                                                 PushAction=LookupCancel;
                                                 InvalidActionAppearance=Hide }
    { 1101339017;CommandButton;11130;5940;2200;550;
                                                 HorzGlue=Right;
                                                 VertGlue=Bottom;
                                                 PushAction=FormHelp }
    { 1101339018;TextBox;220  ;5940 ;4730 ;440  ;Name=TextBox;
                                                 HorzAlign=Right;
                                                 SourceExpr='I am Hidden';
                                                 OnFormat=VAR
                                                            MyCodeunit3@1101339000 : Codeunit 55555;
                                                          BEGIN
                                                            CurrForm.EDITABLE(MyCodeunit3.ShowModify(ISEMPTY,TRUE));
                                                            CurrForm.ButtonModify.VISIBLE(NOT ISEMPTY);
                                                            CurrForm.ButtonShow.VISIBLE(ISEMPTY);
                                                            CurrForm.TextBox.VISIBLE(FALSE);
                                                          END;
                                                           }
    { 1101339019;CommandButton;220;5940;2200;550;Name=ButtonShow;
                                                 HorzGlue=Left;
                                                 VertGlue=Bottom;
                                                 CaptionML=ENU=Show;
                                                 OnPush=VAR
                                                          Mycodeunit1@1101339001 : Codeunit 55555;
                                                        BEGIN
                                                          CurrForm.EDITABLE(Mycodeunit1.ShowModify(ISEMPTY,CurrForm.EDITABLE));
                                                          CurrForm.ButtonModify.VISIBLE(NOT CurrForm.EDITABLE);
                                                          CurrForm.ButtonShow.VISIBLE(CurrForm.EDITABLE);
                                                        END;
                                                         }
    { 1101339020;CommandButton;220;5940;2200;550;Name=ButtonModify;
                                                 HorzGlue=Left;
                                                 VertGlue=Bottom;
                                                 CaptionML=ENU=Modify;
                                                 OnPush=VAR
                                                          Mycodeunit2@1101339001 : Codeunit 55555;
                                                        BEGIN
                                                          CurrForm.EDITABLE(Mycodeunit2.ShowModify(ISEMPTY,CurrForm.EDITABLE));
                                                          CurrForm.ButtonModify.VISIBLE(NOT CurrForm.EDITABLE);
                                                          CurrForm.ButtonShow.VISIBLE(CurrForm.EDITABLE);
                                                        END;
                                                         }
  }
  CODE
  {

    BEGIN
    END.
  }
}

OBJECT Codeunit 55555 Test Codeunit
{
  OBJECT-PROPERTIES
  {
    Date=08/05/09;
    Time=16.52.21;
    Modified=Yes;
    Version List=;
  }
  PROPERTIES
  {
    OnRun=BEGIN
          END;

  }
  CODE
  {

    PROCEDURE ShowModify@1101339001(TFIsempty@1101339000 : Boolean;TFExEditable@1101339001 : Boolean) : Boolean;
    BEGIN
      IF TFIsempty THEN
        EXIT(TRUE)
      ELSE
        EXIT(NOT(TFExEditable));
    END;

    BEGIN
    END.
  }
}

-Mirko-
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog

Comments

  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    And what's the point to waste separate codeunit for this ?

    Reagrds,
    Slawek
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • BeliasBelias Member Posts: 2,998
    I have a codeunit that is something like "miscellaneous functions" where i put all the utilities that are not business related...you certainly don't want to put the same function on all your forms ;)
    I wrote "..or a function somewhere"...it's up to the developer where to put it...
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    a function ?? You really need a function for such piece of logic ?

    How about
    CurrForm.EDITABLE(ISEMPTY OR NOT CurrForm.EDITABLE);
    
    instead of
    CurrForm.EDITABLE(Mycodeunit2.ShowModify(ISEMPTY,CurrForm.EDITABLE));
    
    to replace the function:
    PROCEDURE ShowModify@1101339001(TFIsempty@1101339000 : Boolean;TFExEditable@1101339001 : Boolean) : Boolean;
        BEGIN
          IF TFIsempty THEN
            EXIT(TRUE)
          ELSE
            EXIT(NOT(TFExEditable));
        END;
    
    You do not need to define codeunit variable then.

    Slawek
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • BeliasBelias Member Posts: 2,998
    #-o
    you're right!
    friday has been a really bad day ](*,)
    thanks for the suggestion
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • rdebathrdebath Member Posts: 383
    Use an OnFormat trigger; now why didn't I think of that.

    Well here's my tuppence worth.

    For all three controls:
    CurrForm.EDITABLE((ISEMPTY OR NOT CurrForm.EDITABLE) AND WRITEPERMISSION);
    
    For the Modify button.
    IF NOT WRITEPERMISSION THEN
      ERROR(Text100L, TABLECAPTION);
    
    Modify control, Text constants.
    Name	ConstValue
    Text100L	You do not have permission to modify records in the %1 table.
    

    If they don't have write permission, tell them early.
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    edited 2009-05-11
    Yes, use of OnFormat trigger - this is a whole clue of the trick. Nice trick. But visible only to careful reader :).

    Regards,
    Slawek
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • BeliasBelias Member Posts: 2,998
    exactly...the clue is the onformat and visible intaraction...i didn't have time to explain it properly, sorry.
    in other words, onformat works only if visible is true. (it was not so long to explain after all :mrgreen: )
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
Sign In or Register to comment.