Question Status

Suggested Answer
Kevin Murray asked a question on 15 Jul 2013 6:40 AM

I'm new to AX2009, and I have a small task in which we want a form button

enabled or disabled depending upon a user's security.

I created a user group called BTN_BomPrd, and put some code in the ProdTable(enableButtons)

form method which checks to see if the user has that security, and then enables or disables

the BOM button based on if the BTN_BomPrd entry is found in UserGroupList.

This works perfectly for me. If I give myself BTN_BomPrd, I get the button .If I take it

away from myself, it's gone,

The problem is with others. The button (buttonBOM) will disappear, but then will not come back

even when in debug/breakpoint I can see the code executing fine. I can give them security or

take it away, but the button remains invisible.

Is there some form refresh technique I'm missing?

Thanks!

K

------------------------------------------------------------------------code below

void enableButtons()

{

UserGrouplist UserGroupList;

;

select firstOnly UserGroupList

  where UserGroupList.userId == curuserid()

  && UserGroupList.groupId   == 'BTN_BomPrd';  

if (UserGroupList.RecId != 0)

{

    buttonBOM.Visible(true);

   buttonBOM.enabled(prodTable.ItemId      && prodTable.bomId      ? true : false);

}

else

{

  buttonBOM.Visible(false);

}

  buttonRoute.enabled(prodTable.ItemId    && prodTable.RouteId    ? true : false);

}

Reply
Kent Carstens responded on 15 Jul 2013 7:45 AM

You are most likely missing a refresh based upon when exactly the enableButtons method is called.

I think the real question here is why are you writing code to handle this?  Just identify the user groups that you don't want to see this button and remove the menu item security key from them.  In this case its Prod > Misc > BOM.  Take that permission away in the permission tree and you are good to go.

Reply
Kevin Murray responded on 15 Jul 2013 8:20 AM

Thanks for writing, Kent. I think I'm doing code because of the effort it would take to go thru 100s of groups, if you have a good x2009 way I'd appreciate it. Another thing is that it's that production and inside sales people functionally 'share' this form, and they don't want production people having access at that point in time.

I'm still confused to why a refresh would happen for me but not users I have test this.

K

Reply
Suggested Answer
Kent Carstens responded on 15 Jul 2013 8:57 AM

Where is this enablebuttons method in the ProdTable form?  Are you overriding that somewhere in the form?  Try putting your code in the init method.  Else look to see when the enablebuttons method is being called.  

Reply
Kevin Murray responded on 15 Jul 2013 9:41 AM

Kent, This is an overview of the ProdTableCreate form.

Form

  ProdTablecreate (sys,cus)

   Methods

    classDeclaration

    inventDimModiíied

    enableProjPosting

    enableFields

    showProjectcroup

    enableProjld

    enableßuttons      <-------------new code

    setlnventDimld

    init

    itemld

    run                <------------ calls enableButtons

    numberseqFormHandler

    refreshCaller

    updateDesign

    canClose

    changeßOMRouteVersions

    bomld

    inventDimSetupObject

    pbAconfigurable

   Datasource

    ProdTable

     Methods

     Fields

       Itemid

         Methods

           Modified    <------------ calls enableButtons

       BomId

         Methods

           Modified    <------------ calls enableButtons

The enableButton method is being called from 3 places.(1)From Form<ProdTableCreate> method <run>

public void run()

{

   super();

   prodTable_DS.create(true);

   inventDim_DS.create(true);

   if (callerBuffer.RecId && (prodTableFormId == ProdTableFormId::None || prodTableFormId == ProdTableFormId::Project))

   {

       element.setInventDimId();

   }

   else

   {

       element.updateDesign(InventDimFormDesignUpdate::Init);

   }

   element.enableButtons();

   identification_ItemId.setFocus();

}

(2)From Form(ProdTableCreate) Datasource <ProdTable> Field <Itemid> method <Modified>

public void modified()

{

   ;

   prodTable.bomId         = '';

   prodTable.RouteId       = '';

   prodTable.initFromInventTable(InventTable::find(prodTable.ItemId));

   element.setInventDimId();

   // Initialize if not multisited or if site is set

   if (!prodTable.inventTable().siteActive() || inventDim.InventSiteId)

   {

       prodTable.initBOMVersion();

       prodTable.initRouteVersion();

   }

   prodTable_ds.refresh();

   element.enableButtons();

   super();

   // PBA begin

   pbaExecute.visible(element.pbAconfigurable());

   // PBA end

}

(3)From Form(ProdTableCreate) Datasource <ProdTable> Field <BOMid> method <Modified>

public void modified()

{

   super();

   element.enableButtons();

}

The code in enableButtons is generally as follows, I keep modifying it. The idea

was to have the BOM button greyed out if the user did not have security on this

form only or to enable it if he did.

K

void enableButtons()

{

UserGrouplist UserGroupList;

;

select firstOnly UserGroupList

  where UserGroupList.userId == curuserid()

  && UserGroupList.groupId   == 'BTN_BomPrd';  

if (UserGroupList.RecId != 0)

{

   buttonBOM.enabled(prodTable.ItemId      && prodTable.bomId      ? true : false);

}

else

{

  buttonBOM.enabled(false);

}

   buttonRoute.enabled(prodTable.ItemId    && prodTable.RouteId    ? true : false);

}

Reply
Suggested Answer
Kent Carstens responded on 15 Jul 2013 8:57 AM

Where is this enablebuttons method in the ProdTable form?  Are you overriding that somewhere in the form?  Try putting your code in the init method.  Else look to see when the enablebuttons method is being called.  

Reply