web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

enable/disable form control button from action pane of salestable form

(0) ShareShare
ReportReport
Posted on by 123
Hi there, 
here i am going to enable the buttons from form the code is give as follow, but it is not disabling the buttons,
Pls help me out if there are any changes required in the code.
 
I have the same question (0)
  • Layan Jwei Profile Picture
    8,112 Super User 2025 Season 2 on at
    Hi M_R,
     
    What is the condition for disabling? I can see you've defined a new variable "AvailPhysical" then you directly check if it's 0, which means this condition will always be met. I don't think this is what you want, so please explain more as the method you chose might be wrong too. So for example if you want the buttons to be disabled when you first open the form, then you need to out the code on init method. If changing sth on a certain field might affect visibility, you'll also need to put code on modified method. If navigating between a line and a line might change the visibility, then you might need to put code on active method.
     
    But in general, Did you debug the code and see if it enters this class? To know why they are not being disabled.
     
    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • Martin Dráb Profile Picture
    237,912 Most Valuable Professional on at
    I see two big problems:
    1. Your code is called at a wrong time.
    2. It ignores the fact that there is standard logic for this purpose.
    When you open the form or select a record, your code won't be called at all, because it executions only if you save the record. And then your code will run, but then the standard logic kicks and overwrite the enabled flag.
     
    Search code in the form to see where these buttons are used. I believe there is code in SalesTableType (or child classes) to deal with the buttons, but I don't know details without looking into code. Let us know if you can't find it.
     
    Then you should extend the standard logic instead of trying to put your logic to a different place.
  • M_R Profile Picture
    123 on at
    I have created AvailPhysical quantity on the salesline, 
    when we have available physical quantity for all or any time of the line then only the confirmation and confirm button should be enabled,
    secondly for the packing slip, if the user have not done confirmation then he will be unable to do the picking slip it have to throw the error as throw error("Packing slip cannot be done without confirmation.");
    again same thing for the Invoice, if user  have not done packing slip then hen he will be unable to do Invoice which throw the error as throw error("Invoice cannot be done without Packing slip.");
     
    After your suggestions I  have found one code as SalesTableInteraction class but it is giving error for the macros when I put # before setenabled.
     
    [ExtensionOf(classstr(SalesTableInteraction))]
    internal final class XTSSalesTableInteraction_Extension
    {
        protected void enableLineActions()
        {
            next enableLineActions();
            real XTSAvailPhysical;  
            if(XTSAvailPhysical == 0)
            {
                setEnabled(formControlStr(SalesTable,buttonUpdateConfirmation),false);
                setEnabled(formControlStr(SalesTable,buttonUpdateConfirm),false);
            }
            else
            {
                setEnabled(formControlStr(SalesTable,buttonUpdateConfirmation),true);
                setEnabled(formControlStr(SalesTable,buttonUpdateConfirm),true);
            }
            if(formControlStr(SalesTable,buttonUpdateConfirmation),false) && (formControlStr(SalesTable,buttonUpdateConfirm),false))
            {
                    setEnabled(formControlStr(SalesTable,buttonUpdatePackingSlip),false);
                    throw error("Packing slip cannot be done without confirm.");
            }
            else
            {
                    setEnabled(formControlStr(SalesTable,buttonUpdatePackingSlip),true);
            }
            if(formControlStr(SalesTable,buttonUpdatePackingSlip),false)
            {
                setEnabled(formControlStr(SalesTable,buttonUpdateInvoice),false);
                throw error("Invoice cannot be done without Packing slip.");
            }
            else
            {
                setEnabled(formControlStr(SalesTable,buttonUpdateInvoice),true);
            }
        }
  • Suggested answer
    Martin Dráb Profile Picture
    237,912 Most Valuable Professional on at
    I see you indeed need help with location the logic. Stop trying to extend SalesTableInteraction and look at where the actual logic is. Open enableHeaderUpdateJournalActions() (not enableLineActions()) and look at the code. You'll see that the logic deciding whether the buttons should be enabled is in methods like SalesTableType.parmCanConfirmationBeUpdated(). That's what you should extend and return false in your case; you shouldn't try to meddle with any other logic. That will solve many problems with your code that you aren't aware of yet, such as that you're forget proforma buttons.
  • M_R Profile Picture
    123 on at
    i have written code like this, pls suggest if any changes required
     
  • Layan Jwei Profile Picture
    8,112 Super User 2025 Season 2 on at
    Hi M_R,
     
    Again you defined two variables salesTable and XTSAvailPhysical. 
    So how come if (salesTable.SalesId) is going to work? The code will never reach what is inside.
    Also XTSAvailPhysical will always be zero because u defined the variable and used it directly, so the condition for it will always be true.
     
    Thanks,
    Layan Jweihan 
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • Martin Dráb Profile Picture
    237,912 Most Valuable Professional on at
    Well, I already suggested a better solution in my last reply. I'm not sure why you ignored it and rather wrote much more code that is much worse, because it's at a wrong place (as I explained before) and full of bugs. Instead of asking "pls suggest if any changes required", consider the advice your already got.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 559 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 464 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans