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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Class Extension and Form Extension using COC

(0) ShareShare
ReportReport
Posted on by 2

Hi,

     I have created a custom workflow to Enable/Disable the Generate invoice button since there is no Out of the box Workflow for sales Order .

I can able to trigger the Workflow using canSubmitToWorkflow() (form Extension) and it is working fine .

[ExtensionOf(formstr(SalesTableListPage))]
public final class SalesTable_GD_SalesTableWF_Extension
{
    public boolean canSubmitToWorkflow()
    {
        boolean canSubmitToWorkflow= next canSubmitToWorkflow();

        if(SalesTable.WorkflowState == GD_SalesTableWFApprStatus::Draft)
        {
            canSubmitToWorkflow= true;
        }
        return canSubmitToWorkflow;
    }

}

But when I try to add the code in order to enable/ Disable the Button , It triggers only the setButtonSalesOrder() code (Class Extension)  but not the canSubmitToWorkflow() (Form Extension).which is for Workflow. May I know why it doesn't trigger both the classes ?

[ExtensionOf(classStr(SalesTableListPageInteraction))]
final class InvoiceButton_Extension
{

    protected void setButtonSalesOrder()
    {
        SalesTable salesTable = this.currentSalesTable();
        next setButtonSalesOrder();



        if(salesTable.SalesStatus != SalesStatus::Invoiced && salesTable.WorkflowState == GD_SalesTableWFApprStatus::Approved)
        {

            this.listPage().actionPaneControlEnabled(formControlStr(SalesTableListPage,buttonUpdateInvoice), true);

        }
        else //if(salesTable.SalesStatus == SalesStatus::Invoiced)
        {

            this.listPage().actionPaneControlEnabled(formControlStr(SalesTableListPage,buttonUpdateInvoice), false);

        }
        
    }

}

I have the same question (0)
  • Martin Dráb Profile Picture
    239,688 Most Valuable Professional on at

    Sorry, but I don't understand. You're saying that canSubmitToWorkflow() is working fine, but also tha it doesn't "trigger". So is it working fine or not?

    Also, why should your extension of setButtonSalesOrder() trigger canSubmitToWorkflow()? All you do that is changing a property of ma button.

  • NoobGamer Profile Picture
    2 on at

    When I just add  canSubmitToWorkflow() method to my project . I can able to see the workflow button in the action pane .

    I have debugged the code,  canSubmitToWorkflow() is getting triggered each time when I select each record in the SalesTableListPage form and when I select each record, For every record I can able to see the WorkFlow button in the Action pane .

    And when I try to add the Extension for SalesTableListPageInteraction class Workflow button is disabled and It does not trigger the canSubmitToWorkflow() method

    since setButtonSalesOrder() is present inside the setButtonEnabled() method and this method is called  every time when the selection of the record in the list page changes.

    So I have Extended SalesTableListPageInteraction class using COC and added some code in setButtonSalesOrder() so that I could enable/disable the button by checking the values present in the custom Enum field(WorkflowState) and SalesStatus Field .

  • Verified answer
    Martin Dráb Profile Picture
    239,688 Most Valuable Professional on at

    Setting visibility of buttonUpdateInvoice in setButtonSalesOrder() looks wrong to me. Also, the fact that you're ingoring all standard logic looks very dangerous. For example, the system hides the invoice button if the customer is blocked, but you'll show it again.

    First of all, the method setting visibility of buttonUpdateInvoice is setButtonInvoice(), not setButtonSalesOrder(). But even that isn't the place where the decision is made. That's done in SalesLTableType.canInvoiceBeUpdated() and that would be a much better place for your logic.

  • NoobGamer Profile Picture
    2 on at

    Thanks Martin . This method worked for me .But how to find these things ? Do you Debug the standard code ?

  • Martin Dráb Profile Picture
    239,688 Most Valuable Professional on at

    I didn't debug code; I just looked into code without running it.

    I opened SalesTableListPageInteraction class and searched for buttonUpdateInvoice. This led me to setButtonInvoice(), where buttonUpdateInvoice is enabled based on canInvoiceBeUpdated variable. Therefore I looked for where canInvoiceBeUpdated is set, which is in initCanBeUpdated() and I noticed that the key piece is salesTable.checkIfUpdate(). I highlighted this method and pressed F12, which took me into its definition. There is the call of this.type().checkIfUpdate(). I went inside, looked for invoce-related logic and found the call of this.canInvoiceBeUpdated().

  • NoobGamer Profile Picture
    2 on at

    Hi Martin ,

                 I have some doubt which is similar to the above requirement , but here I am not using any Workflow .

    Based on the Enum Field(Reference Document Type) Can I able to Enable/ Disable the add Lines Button in the Lines for InventSiteInwardGateEntry_IN form (India Based Legal Entity Form).

    pastedimage1664304547311v1.png

    I should I created a new thread , Since it is similar to the above requirement I have asked here . Can you please confirm whether it is possible to Enable?Disable the Add Lines Button based on Enum type in the header

  • GirishS Profile Picture
    27,843 Moderator on at

    Hi NoobGamer,

    Yeah you can do this by extension. On the form datasource "InventSiteGateEntry_IN" "active" method you can add the condition.

    If(InventSIteGateEntry_IN.Reference type == enumvalue)
    {
        InventSIteGateEntryLine_IN.allowCreate(false);
    }
    else
    {
        InventSIteGateEntryLine_IN.allowCreate(true);
    }

    Thanks,

    Girish S.

  • NoobGamer Profile Picture
    2 on at

    Thanks Girsh But Whether can I able to Enable/Disable the Same Reference Document Type Field  based on Custom Enum Field Value with affecting the standard functionality of the Reference Document Type Field .

    Because that field already has the disable/Enable Functionality . 

  • GirishS Profile Picture
    27,843 Moderator on at

    Hi NoobGamer,

    Yeah you can create a new custom enum and based on that enum you can enable disable the new button.

    Thanks,

    Girish S.

  • Martin Dráb Profile Picture
    239,688 Most Valuable Professional on at

    NoobGamer, the verified answer didn't answer your question because you have a different requirement and it's about a different form. Don't change the topic - create a new thread instead. You can always as links to related threads.

    What you can take from this thread is the process of finding how the existing logic works.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

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

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 681 Super User 2026 Season 1

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 551 Super User 2026 Season 1

#3
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 471

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans