Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

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

(0) ShareShare
ReportReport
Posted on by 125
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.
 
  • Martin Dráb Profile Picture
    Martin Dráb 230,370 Most Valuable Professional on at
    enable/disable form control button from action pane of salestable form
    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.
  • Layan Jwei Profile Picture
    Layan Jwei 7,347 Super User 2024 Season 2 on at
    enable/disable form control button from action pane of salestable form
    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
  • M_R Profile Picture
    M_R 125 on at
    enable/disable form control button from action pane of salestable form
    i have written code like this, pls suggest if any changes required
     
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,370 Most Valuable Professional on at
    enable/disable form control button from action pane of salestable form
    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
    M_R 125 on at
    enable/disable form control button from action pane of salestable form
    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);
            }
        }
  • Martin Dráb Profile Picture
    Martin Dráb 230,370 Most Valuable Professional on at
    enable/disable form control button from action pane of salestable form
    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.
  • Layan Jwei Profile Picture
    Layan Jwei 7,347 Super User 2024 Season 2 on at
    enable/disable form control button from action pane of salestable form
    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

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

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans