Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Supply chain | Supply Chain Management, Commerce
Answered

Hiding menu item using COC

(1) ShareShare
ReportReport
Posted on by 2,291
Hi Experts,
 
I am trying to hide(visible=false) menu item "buttonUpdatePackingSlip" for specific user. I created a table and assign userid there and checking userid if exists hide the menu button.
But getting error using below code.
 
[ExtensionOf(formStr(SalesTable))]
public final class SFA_SalesTable_Packingslip_Extension
{

    public void init()


    {
        next    init();

        if (this.isUserInConfig())
        {
            // Find the "Generate Packing Slip" button and make it invisible
            FormButtonControl packingSlipButton = this.design().controlName('buttonUpdatePackingSlip');
            if (packingSlipButton)
            {
                packingSlipButton.visible(false);
               
            }
        }

    }

    private boolean isUserInConfig()
    {
        SFA_PackingSlip_UserId userConfig;
        select firstOnly RecId from userConfig
            where userConfig.UserId == curUserId();
        return userConfig.RecId != 0;
    }

    

}
 
Thanks,
Faiz
  • Martin Dráb Profile Picture
    234,542 Most Valuable Professional on at
    Hiding menu item using COC
    Am sorry, but you're the only one who can debug the code in your environment and see why the button's visibility is set to No. I don't see anything I can do for you. If you try to debug it but didn't identify the cause, then your debugging wasn't successful and you should continue. Didn't you forget to remove the system administrator role?
  • faiz7049 Profile Picture
    2,291 on at
    Hiding menu item using COC
    Hi Martin,
     
    In debug I did not find issue. I just want to know why this customization only works if user has System Administrator role. Since this customization is not based on role.Again I am asking should I have to privilege role for Table/Form SFA_PackingSlip_ItemGroup and assigned to user role  or it’s not required. Problem is something else.
     
    Your prompt action will be appreciated.
     
    Thanks,
    Faiz
  • Martin Dráb Profile Picture
    234,542 Most Valuable Professional on at
    Hiding menu item using COC
    I'm sorry, but I'm unable to debug what's going on in your environment. First of all, verify that it's the code in salesLine_OnActivated() that causes the problem and then use the debugger to see where things go wrong.
  • faiz7049 Profile Picture
    2,291 on at
    Hiding menu item using COC
    Hi Martin,
     
    I am facing issue that this customization only works if we give System Administrator role to use other-wise its always visible false even item group is defined in SFA_PackingSlip_ItemGroup table.
     
    Should I need to create security privilege on SFA_PackingSlip_ItemGroup table and give access to user.
     
    Please help me.
     
    Thanks,
    Faiz
  • faiz7049 Profile Picture
    2,291 on at
    Hiding menu item using COC
    Thank you Martin for describing Auto Declaration.
    I want to apply same login as SalesTable form on SalesTableListPage . How can be possible means SalesLine is not available on SalesTableListPage.
     
     
  • Martin Dráb Profile Picture
    234,542 Most Valuable Professional on at
    Hiding menu item using COC
    Auto Declaration = No is no problem. You aren't using the variable at all, and if you used CoC and refer to the variable, you'd find that it works even without Auto Declaration. That applies when you're making changes in the form itself, not in extensions.
  • faiz7049 Profile Picture
    2,291 on at
    Hiding menu item using COC
    Thank you Martin, Below code is working. I want to do same on SalesTableListPage form but there how can I do. There AutoDeclaration is false.
     
     
       [FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesLine), FormDataSourceEventType::Activated)]
        public static void salesLine_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
        {
           SalesLine salesLine = sender.cursor();
           InventTable inventTable = salesLine.inventTable();
            FormRun formRun = sender.formRun();
            FormFunctionButtonControl packingSlipButton = formRun.design().controlName(formControlStr(SalesTable, buttonUpdatePackingSlip)) as  FormFunctionButtonControl;
          if (inventTable)
            {
               ItemGroupId itemGroupId = inventTable.itemGroupId();
               if (SFA_SalesTable_ItemId_PackingSlip_EventHandler::isItemGroup(itemGroupId))
              {
                    
                 packingSlipButton.visible(true);
               }
                else
    
                {
                    packingSlipButton.visible(false);
                }
              
              }
        }
        
       private static boolean isItemGroup(ItemGroupId _itemGroupId)
      {
           SFA_PackingSlip_ItemGroup packingItemGroup;
        
         select  * from packingItemGroup
            where packingItemGroup.ItemGroupId == _itemGroupId;
    
          return packingItemGroup.RecId != 0;
       }
     
  • Verified answer
    Martin Dráb Profile Picture
    234,542 Most Valuable Professional on at
    Hiding menu item using COC
    When you know where the error occurs, look at which variable is null. It seems to be packingSlipButton, therefore your code for getting a reference of the button doesn't seem to work.
     
    I think that controlName() returns the button reference correctly, but you get null when you try to cast it to FormButtonControl, because it's not an instance of FormButtonControl class. The right type is FormFunctionButtonControl, I think. You can verify that by looking at what you get from controlName().
  • faiz7049 Profile Picture
    2,291 on at
    Hiding menu item using COC
    Hi Martin,
     
    In Debugged, Following error is coming.
     
  • Martin Dráb Profile Picture
    234,542 Most Valuable Professional on at
    Hiding menu item using COC
    Hmm, I don't think that customer's requirement is that the button will never appear again and users will have to restart the form to be able post any packing slip. You should make the button visible if isItemGroup return false.
     
    I didn't test the code; there may be some mistakes. The error means that we're trying to use (typically to call a method) on a variable that contains null instead of an object reference. Use the debugger to see which variable it's about.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Supply chain | Supply Chain Management, Commerce

#1
Laurens vd Tang Profile Picture

Laurens vd Tang 171 Super User 2025 Season 1

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 140 Super User 2025 Season 1

#3
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 127 Super User 2025 Season 1

Featured topics

Product updates

Dynamics 365 release plans