Skip to main content
Dynamics 365 Community / Forums / Finance forum / To disable buton on fo...
Finance forum
Suggested answer

To disable buton on form using the checkbox on custom form

editSubscribe (1) ShareShare
ReportReport
Posted on by 1,292
hi ,
Everyone ,
I have created the custom form where i have added the check box if i ticked the checked box create new in my custom form i need to disable the new button in sales order form .
do i need to code on sales order active method but how can i fetch the from control of my custom form.
here i my custom form .please guide me on this 
thanks,
Regard,
Dinesh
Attachments
  • Martin Dráb Profile Picture
    Martin Dráb 222,727 Super User on at
    To disable buton on form using the checkbox on custom form
    You're lucky! If you believed that your code worked and shipped it, you would break your customers ERP system! You must be more careful.
     
    There already is standard logic to decide whether a confirmation can be posted, which your completely ignore. If you managed to overwrite the value, you'd have break the standard logic. Also, if you want to prevent confirmation posting, you need to take all the related buttons into account. All the button will be handled if you do it at the right place: SalesTableType.canConfirmationBeUpdated(). What you should have done is considering that standard logic may exist (if you don't already know that the buttons are disabled in some case, which proves that some logic must exist). Then you should have used Find references to find the place and analyze code further to find the right place to extend.
     
    Your handling of LineStripNew is wrong too. I'm assuming that you want to prevent line creation, but you didn't. You disabled a button but users can still use keyboard shortcuts. The correct approach is using allowCreate() of salesLine_ds.
     
    Also, the while select makes no sense, because only values from the last record will be used. Loading all the previous records is a waste of resources. If there are more records in DTSalesTransactionAccess for a single user, add condition to your code to decide which one to use.
     
    You can throw away your select of userInfo and the salesLine variable.
     
    If accessing the button was the correct thing to do, you could greatly simplify your code by using element object to access the form. Then you can use, for example, element.buttonUpdateConfirm to access the confirmation button.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,292 on at
    To disable buton on form using the checkbox on custom form
    hi 
    Thanks
    For reply ,
    I was trying to enable and disable the button on current user but , the button add line on the salestable form is getting enable disable but the menuitem button is not getting disable as i have debugged the code debugger is hitting the condition . please guide me is anything i need to change to disable menuitem button .below is my code.
    [ExtensionOf(formdatasourceStr(SalesTable, SalesTable)) ]
    final class DTSalestableForm_AssignTransactionAccess_Extension
    {
        public int  active()
        {
            UserId    userid ;
            UserInfo  userInfo;
            DTSalesTransactionAccess      salesAccess;
            SalesTable        salesTableLoc = this.cursor();
            SalesLine         salesLine;
    
            int ret = next active();
    
            userid = curUserId();
            select id from  userInfo
                where userInfo.id == userid;
    
          while select * from salesAccess
                where salesAccess.UserId == userInfo.id
            {
                if(salesAccess.RecId != 0 && salesAccess.inventLocationId == salesTableLoc.InventLocationId)
                {
                  
                     
                        if(salesAccess.Addlines == NoYes::Yes)
                        {
                            this.formrun().design().controlName(formControlStr(SalesTable, LineStripNew)).enabled(true);
                        }
                        else
                        {
                            this.formrun().design().controlName(formControlStr(SalesTable, LineStripNew)).enabled(false);
                        }
    
                   
                        if(salesAccess.Confermation == NoYes::Yes)
                        {
                            this.formrun().design().controlName(formControlStr(SalesTable, buttonUpdateConfirm)).enabled(true);
                        }
                        else
                        {
                            this.formrun().design().controlName(formControlStr(SalesTable, buttonUpdateConfirm)).enabled(false);
                        }
    
                       
                 
                }
                else
                {
                    this.formrun().design().controlName(formControlStr(SalesTable, LineStripNew)).enabled(true);
                    this.formrun().design().controlName(formControlStr(SalesTable, buttonUpdateConfirm)).enabled(true);       
                }
            }
               
            return ret;
        }
    
    }
     
  • Waed Ayyad Profile Picture
    Waed Ayyad 2,029 on at
    To disable buton on form using the checkbox on custom form
    Hi
     
    Can you explain your requirements in another way, as your comment isn't clear?
     
     
    Thanks,
    Waed Ayyad
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 222,727 Super User on at
    To disable buton on form using the checkbox on custom form
    Yes, you'll want to check your condition when a sales order is selected, therefore in active().
     
    You didn't describe the logic you want, e.g. whether you want to somehow check warehouses of all lines in the given order, therefore I can't tell you exactly you can implement these unknown requirements. But in general, you'll decide which record in your table you're interested in, you'll find it (by find() method, select statement or so) and then you'll get the field value (e.g. myTable.MyField).

Helpful resources

Quick Links

New Blog Features Released!

Check out the new community blog features for viewers and authors…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,176 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,727 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Featured topics

Product updates

Dynamics 365 release plans