Enable/Disable Menu Items in Menu Button

sanjeevasawalesanjeevasawale Member Posts: 63
Friends,

I searched for the solution but couldn't get.

Actually, I wanted disable one Menu Item in Menu Button based on some condition.

Can this be done. I can do other way round that is, write code in that menu item to restrict its functionality.

Please guid better way.

Thx,

Sanjeev

Comments

  • Hi,

    Do one thing. make another menu button(MB2) and make the menu item disable (which u want to disable by making visible to No). put this menu button on ur previos menu button(MB1). now add following line of code to OnOpen Form:

    if <Condition> Then begin
    Currform.MB1.visible := False;
    Currform.MB2.visible := True;
    end
    else begin
    Currform.MB1.visible := true;
    Currform.MB2.visible := false;
    end;

    Regards,
    Gaurav
    Gaurav Sharma,
    Consultant-Microsoft Dynamics Nav
  • SavatageSavatage Member Posts: 7,142
    Assign a value to the Name property of a command or menu button then you can dynamically set the Enabled or Visible properties of the control in the trigger code using C/AL commands.

    For example, to disable a menu button that has the value of the Name property set to btnCustomer, you would use the following command:

    CurrForm.btnCustomer.ENABLED(FALSE);

    Unfortunately, there is not a method to dynamically control the individual menu items of a menu button. However, it would be possible to create two different menu buttons with different Name property values. These two button controls could then be stacked on top of each other and trigger code added to the form to make one button visible and one button not visible, based upon the desired criteria.

    For example, to control which menu button is displayed, based on the existence of a customer email address, where the button controls were named btnCustomer1 and btnCustomer2, you would use the following code in the OnAfterGetCurrRecord trigger:

    IF "E-Mail" = '' THEN BEGIN
    CurrForm.btnCustomer1.VISIBLE(TRUE);
    CurrForm.btnCustomer2.VISIBLE(FALSE);
    END ELSE BEGIN
    CurrForm.btnCustomer1.VISIBLE(FALSE);
    CurrForm.btnCustomer2.VISIBLE(TRUE);
    END;

    **EDIT**

    Ooops already posted
  • sanjeevasawalesanjeevasawale Member Posts: 63
    Friends,

    I feel u didnt get my problem. I wanted to enable/disable the Menu Item in Menu Button and not Menu Button. I know menu button can be enabled/disabled. I wanted to enable/disable the 1 or more Menu Items in Menu Button.
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    You can't.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • DenSterDenSter Member Posts: 8,307
  • WaldoWaldo Member Posts: 3,412
    nicht meuglich 8-[

    :wink:

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • ara3nara3n Member Posts: 9,257
    nicht immer, aber immer oefter.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • hi,
    i have understood ur proble and already sent u the solution 4 the same. agin i m sending:


    make another menu button(MB2) and make the menu item disable (which u want to disable by making visible to No(untick it)) . put this menu button on ur previos menu button(MB1). now add following line of code to OnOpen Form:

    if <Condition> Then begin
    Currform.MB1.visible := False;
    Currform.MB2.visible := True;
    end
    else begin
    Currform.MB1.visible := true;
    Currform.MB2.visible := false;
    end;

    Regards,
    Gaurav
    Gaurav Sharma,
    Consultant-Microsoft Dynamics Nav
  • sanjeevasawalesanjeevasawale Member Posts: 63
    Dear Gaurav,

    Thx for ur efforts of putting it again. Your suggestion will work only when it will be only 1 or 2 conditions. But think the case where for different reasons (multiple conditions) will be there then I can not have multiple buttons. I should be able to simply enable/disable the items based on multiple conditions.

    for example:
    condition 1 will disable menu item 2
    condition 2 will disable menu item 5
    condition 3 will disable menu item 8
    condition 4 will disable menu item 10

    I hope u got what I mean to say.
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    I should be able to simply enable/disable the items based on multiple conditions.

    We should all be able to simply enable/disable individual menuitems ... but we can't. It is so by design.
    I think you have to live with it. Sorry :cry:
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • DenSterDenSter Member Posts: 8,307
    <snip>
    I should be able to simply enable/disable the items based on multiple conditions.
    </snip>
    ... but you can't, it is simply not possible in Navision. You can ask the same question multiple times, but the fact remains that it is not possible.

    If you want something that looks like a dynamic menubutton you will have to use the trick posted by Guarav.
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    Do I hear an echo ;-)
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • DenSterDenSter Member Posts: 8,307
    I was waiting for Waldo to do the same :mrgreen:
  • sanjeevasawalesanjeevasawale Member Posts: 63
    Hey Black ?,

    U got it wrong. M not under estimating anyone or thinking people are fool here. I thought people miss-understood my query so written it again.
  • apankoapanko Member Posts: 70

    for example:
    condition 1 will disable menu item 2
    condition 2 will disable menu item 5
    condition 3 will disable menu item 8
    condition 4 will disable menu item 10

    I hope u got what I mean to say.

    Try this :D
    Not exactly you want but ...

    Trigger onPush of ComandButton

    var bool1,bool2,bool3 - boolean - or your conditions
    var OptionString, NewString - text 250
    OptionString:='';
    
    IF bool1 THEN
      IF OptionString='' THEN
        OptionString:='menu 1'
      ELSE
        OptionString:=OptionString+',menu 1';
    IF bool2 THEN
      IF OptionString='' THEN
        OptionString:='menu 2'
      ELSE
        OptionString:=OptionString+',menu 2';
    IF bool3 THEN
      IF OptionString='' THEN
        OptionString:='menu 3'
      ELSE
        OptionString:=OptionString+',menu 3';
    
    NewString := SELECTSTR(STRMENU(OptionString),OptionString);
    
    CASE NewString OF
      'menu 1':BEGIN
        MESSAGE('Menu 1 action. May be open list form');
      END;
      'menu 2':BEGIN
        MESSAGE('Menu 2 action.');
      END;
      'menu 3':BEGIN
        MESSAGE('Menu 3 action.');
      END;
    END;
    
  • Joe_MathisJoe_Mathis Member Posts: 173
    I'm not sure exactly what you are looking for but it sounds like you want to disable menu items for certain users which sounds like security to me.

    A post was made a while ago about security roles and how the ones from Microsoft don't seem to work. A idea was put forth that you should start out with giving the users everything. Not just Table/Form/Report 0, but list every table/form/report/codeunit/etc by number and granting permissions. Then as you want to restrict users and tighten security you take away the permissions from all users and create a new group of users that have these permissions.

    I was testing this out and found it works very well, especially if you just remove permissions for the forms they have no need to see.

    (And now I get to the point!) :D

    If what you are trying to do is not allow the users to see a form/report/dataport all you have to do is take away their permission to view that object and they cannot see it in the Menu. This makes their security the condition and it does it automatically without extra coding. If their security changes in the future to allow them that object then it will be back on their menu.

    Of course it is a little more involved to set up but it does tighten security a lot in the process and who doesn't want that?

    Hopefully this helps,

    Joe
Sign In or Register to comment.