Dynamically Hide/Show Page Menu Items In RTC

kirtangorkirtangor Member Posts: 65
edited 2013-03-06 in NAV Three Tier
I am using NAV 2009 SP1, and developing a page for the RTC.

I am using an expression (a boolean variable) to hide/show a menu item (using VISIBLE property) in the "Related Information" menu. Everytime a new record is fetched, I update the boolean variable in the OnAfterGetRecord() event.

For example, when the form opens the boolean variable is set to FALSE, and the items is not shown. When I navigate to the next record, the variable gets set to TRUE, and the item shows up. Everything works fine till this point. The problem occurs when I move to the previous record again - the variable gets set to FALSE (as it should), but the menu item is still visible, and remains visible until the form is closed.

I tried setting the ENABLED property instead of the VISIBLE property for the menu item, and it works as it should (gets enabled when the boolean variable is TRUE, and vice versa). But something seems to be wrong with the VISIBLE property.

Has anyone faced something like this? Any solutions are welcome!
Thanks,
Kirtan.

Comments

  • manisharma31manisharma31 Member Posts: 285
    Hi,
    Visible property work differently in RTC.
    Just go through page id. 1 (Company Information).
    Check the Property fiel of the boolen fields (IncludeInDataset).

    May be this should solve you problem.
    Regards,
    Manish
  • kirtangorkirtangor Member Posts: 65
    Thanks for the reply Manish.

    But, I know how to use the Visible property (creating a boolean variable, and setting the IncludeInDataset property, binding that variable to the relevant property of a control).

    I am doing it correctly. The menu item remains hidden initially. But, once it becomes visible while traversing other records, it doesn't get invisible again.

    You can try this scenario yourselves -

    Modify the customer card page by adding a menu item to it (set the RunObject property to open any list page, etc.). Create a boolean variable, set the IncludeInDataset property of that variable, assign it to the menu item's visible property. Set the value of the boolean variable in the OnAfterGetRecord() event of the page -
    DynamicVar := ("Location Code" <> 'YELLOW');
    
    What this piece of code will do is set the Visible property of the menu item dynamically based on the value of the Location Code field.

    Run the customer list, and select a record where the location code is "Yellow". You'll observe that the menu item remains invisible. Try traversing using Ctrl+PgUp/Ctrl+PgDn and go to a record where location code is not "Yellow". The menu item becomes visible. Now, when you traverse to the previous records where the menu item was invisible, you'll observe that the item is still visible!

    This, in detail, is the problem I am facing. I don't know whether this is by design, or a bug in Microsoft's code.
    Thanks,
    Kirtan.
  • bruno77bruno77 Member Posts: 62
    I have the same issue, is there a solution to this?
  • kirtangorkirtangor Member Posts: 65
    No solution yet, but I used a workaround in which I enabled/disabled that item instead of hiding/showing it. It works like a charm.
    Thanks,
    Kirtan.
  • smalkmussmalkmus Member Posts: 18
    When does NAV use this property to setup the fields on a page? I have a similar but different issue. I have a page with a combo box and a text box. If the first option is selected in the combo box, the text box should be visible. If any other option is selected, the text box should not be visible. I have created a global variable (IncludeInDataSet = Yes) and assigned it to the text box's visible property. I created a function to set the variable and call it in the OnOpenPage() function and the OnValidate() (of the combo-box control) function. When the page opens, the text box is shown/hidden correctly but if I change the combo box, I can see that the variable is correctly set but the text box control does not hide/show. Is there something I'm missing?

    Kirtangor, I hope you don't mind me posting my issue here. I don't want to hi-jack your thread but I think this is a similar issue so I posted in here rather than creating a new thread. Please let me know if that's not OK. And if anyone has a solution or knows where I'm going wrong, please let me know.

    Thanks!
  • kirtangorkirtangor Member Posts: 65
    Ummm, that's a weird issue. If you are doing, what you have mentioned you are doing, then it must work.

    I have also written same type of code for a group box in a page; I am hiding/showing it on the basis of an option-based dropdown list. Its working perfectly for me.

    I am using NAV 2009 SP1. Which version are you using?
    Thanks,
    Kirtan.
  • rdebathrdebath Member Posts: 383
    Just a thought, you should probably both post build numbers as MS are finding LOTS of bugs in the RTC.
  • smalkmussmalkmus Member Posts: 18
    rdebath wrote:
    Just a thought, you should probably both post build numbers as MS are finding LOTS of bugs in the RTC.

    That's a good idea. I'm on NAV 2009 SP1, build 6.0.29626.0. I checked partnersource and I don't see any other hotfixes or updates to NAV after 2009 SP1.

    Just in case I'm doing something stupid, let me explain exactly what I've done.

    My page has a global boolean variable IsControlVisible {IncludeInDataset = Yes}. I've assigned this variable to the Visible property of the text box. I set the variable based on the selection of the combo box in the OnOpenPage function. This works perfectly. When the page opens, the text box is shown or hidden as it should be. Next, I added the same code to the OnValidate() function of the combo box control. When I change the combo box selection, nothing happens. I put a message box in the code to confirm the value of the boolean variable and it is correctly updating to true or false as it should. Is there anything wrong with this? I guess my main concern is whether the visible property of the control is taken into account at times other than the OnOpenPage() function. From what I can tell, it seems that NAV sets the property when the page opens and never looks at it again. Any suggestions would be greatly appreciated!
  • kirtangorkirtangor Member Posts: 65
    I looked into your scenario, and, you are right. Its not working. Seems that the visibility of data bound controls like textbox can be set on/off only in the OnOpenPage trigger.

    I had done this with a group box, and it works fine that way. You can take a look at the code that I have appended to this post.

    In the code example, the page is bound to the Resource table. When the type of the resource is set to Person, it will show the City group box, else it will hide it. As you will see, the City textbox itself does not hide/shown when the type value changes.
    OBJECT Page 50000 Resource Card 2
    {
      OBJECT-PROPERTIES
      {
        Date=04/28/10;
        Time=10:01:15 AM;
        Modified=Yes;
        Version List=CUS01;
      }
      PROPERTIES
      {
        SourceTable=Table156;
        PageType=Card;
        OnAfterGetRecord=BEGIN
                           IsCityVisible := (Type = Type::Person);
                         END;
    
      }
      CONTROLS
      {
        { 1100495000;0;Container;
                    ContainerType=ContentArea }
    
        { 1100495001;1;Group  ;
                    Name=General;
                    GroupType=Group }
    
        { 1100495002;2;Field  ;
                    SourceExpr="No." }
    
        { 1100495003;2;Field  ;
                    SourceExpr=Type;
                    OnValidate=BEGIN
                                 IsCityVisible := (Type = Type::Person);
                               END;
                                }
    
        { 1100495004;2;Field  ;
                    SourceExpr=Name }
    
        { 1100495005;2;Field  ;
                    SourceExpr="Search Name" }
    
        { 1100495008;2;Field  ;
                    SourceExpr=City;
                    Visible=IsCityVisible }
    
        { 1100495007;1;Group  ;
                    CaptionML=ENU=City;
                    Visible=IsCityVisible;
                    GroupType=Group }
    
        { 1100495006;2;Field  ;
                    SourceExpr=City }
    
      }
      CODE
      {
        VAR
          IsCityVisible@1100495000 : Boolean INDATASET;
    
        BEGIN
        END.
      }
    }
    
    Thanks,
    Kirtan.
  • rdebathrdebath Member Posts: 383
    smalkmus wrote:
    rdebath wrote:
    Just a thought, you should probably both post build numbers as MS are finding LOTS of bugs in the RTC.

    That's a good idea. I'm on NAV 2009 SP1, build 6.0.29626.0. I checked partnersource and I don't see any other hotfixes or updates to NAV after 2009 SP1.
    There's loads of them here:

    https://mbs.microsoft.com/knowledgebase/search.aspx

    And an example hotfix download.
    http://support.microsoft.com/hotfix/KBH ... num=982140

    Unfortunately, I've also found kb969016 and it says 'Broken As Designed'. :x

    PS: Direct link to KB canned as some MS reps are idiots.
  • smalkmussmalkmus Member Posts: 18
    Thanks a lot for the replies and thanks for the code sample kirtangor. I will just have to live with setting the field's enabled property rather than the visible this time.
  • eYeeYe Member Posts: 168
    It was an issue in NAV2009, fixed in NAV2009 R2 and now back again in NAV2013...

    Well, confirmed that Expressions for Properties do work on Lists and Cards, it does not work for CardParts on the Role Center Page.
    Kind Regards,
    Ewald Venter
Sign In or Register to comment.