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

Community site session details

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

How to access Buttons using formDataSourceStr COC

(0) ShareShare
ReportReport
Posted on by 2

Hi ,

   How can I access the UI Buttons using formDataSourceStr COC. When I try to access the buttonInvoiceUpdate inside the class I am getting the following Error

[ExtensionOf(formDataSourceStr(SalesTableListPage,SalesTable))]
final class SalesTable_SalesTable_Extension
{
    public int active()
    {                SalesTable salesTable= this.cursor();
        FormButtonGroupControl CourseCertificate = this.formRun().design().controlName("buttonUpdateInvoice") as FormButtonGroupControl;
        int ret = next active();
            buttonUpdateInvoice.enabled(salesTable.SalesStatus != SalesStatus::Invoiced && salesTable.WorkflowState == GD_SalesTableWFApprStatus::Approved);
        return ret;
    }
}

pastedimage1655154729357v1.png

I have the same question (0)
  • Martin Dráb Profile Picture
    235,966 Most Valuable Professional on at
    RE: How to access Buttons using formDataSourceStr COC

    Your code should work if the form returned from formRun() has a control called buttonUpdateInvoice and the type of this control is FormButtonGroupControl. Please test all these assumptions.

    Also, if you know the form name in advance, please use formControlStr() instead of hard-codeding the control name.

    Where are you calling your code?

    By the way, why is the variable called courseCertificate?

  • rohit1900 Profile Picture
    439 on at
    RE: How to access Buttons using formDataSourceStr COC

    Hi I tried similar functionality

    where I  have added a new button in the form action pane and I am calling on form datasource for enable/disable

    i was getting error while debugging "object reference not set "

    but this line 

    FormButtonGroupControl CourseCertificate = this.formRun().design().controlName("buttonUpdateInvoice") as FormButtonGroupControl;

    CourseCertificate  returns null

    returns null for me  and ultimately giving me error object reference not set  how to resolve this issue

  • Martin Dráb Profile Picture
    235,966 Most Valuable Professional on at
    RE: How to access Buttons using formDataSourceStr COC

    You're getting an error because you've never declared any variable called buttonUpdateInvoice. You've put the button to a variable called courseCertificate (which you never used).

    Also, never hard-code object names as strings, because then compiler can't found the problem if a button gets renamed or something. Use intrinsic functions such as formControlStr().

  • AnithaEswaran Profile Picture
    2,032 on at
    RE: How to access Buttons using formDataSourceStr COC

    Can you try this ? 

    public int active()
        {
            int ret;
      
            ret = next active();
            
            SalesTable salesTable = this.cursor();
           
    		FormButtonGroupControl invoiceBtn = this.formrun().design().controlName(formControlStr(SalesTableListPage, buttonName)) as FormButtonGroupControl;
            
            invoiceBtn.enabled(<<<>>>)
    		
    
            return ret;
        }
    

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

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

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 823 User Group Leader

#2
André Arnaud de Calavon Profile Picture

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

#3
Martin Dráb Profile Picture

Martin Dráb 491 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans