Easy to implement Show/Modify Feature

Belias
Member Posts: 2,998
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
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. } }
0
Comments
-
And what's the point to waste separate codeunit for this ?
Reagrds,
SlawekSlawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
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...0 -
a function ?? You really need a function for such piece of logic ?
How aboutCurrForm.EDITABLE(ISEMPTY OR NOT CurrForm.EDITABLE);
instead ofCurrForm.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;
SlawekSlawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
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.Robert de Bath
TVision Technology Ltd0 -
Yes, use of OnFormat trigger - this is a whole clue of the trick. Nice trick. But visible only to careful reader
.
Regards,
SlawekSlawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
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)
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions