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, ...
Answered

How we can access the global variable/method declared at form extension class

(1) ShareShare
ReportReport
Posted on by 87
Hi All,
 
I have created a form extension class where i have declared a global variable. Similarly i have created a form datasource extension class. In this class i want to access the variable which is declared in the form level extension. Can anyone help, how can i access the global variable?
 
[Extensionof(formStr(ProdTableCreate))]
final class ProdtableCreate_Extension
{
     Public PIDPackageRequestHeader        packageRequestHeader;
 
     public void init()
     {
          next init();
          if(this.args().dataset() == tableNum(PIDPackageRequestHeader))
          {
               packageRequestHeader = this.args().record();
           
           }
      }
}
 
[ExtensionOf(formDatasourceStr(ProdTableCreate, PIDProdTable))]
final class ProdTableCreate_Prodtable_Extension
{
    PIDProdTable pidProdTable = this.cursor();
    public void initValue()
    {
        // I want to access the packagerequestHeader variable
        if(packageRequestHeader) // I am gettting error variable not declared
        {
                  pidProdTable.PackagingRequest = packageRequestHeader.PackagingRequest;
        }
}
 
Can anyone help us how i can access it.
 
I have the same question (0)
  • Verified answer
    GirishS Profile Picture
    27,827 Moderator on at
    Hi Neeraj,

    Since you are getting the caller dataset and caller record - You can get the form run inside the DataSource extension class and get the caller object and caller record.
    FormRun fRun = this.formRun();
    //add code to get the caller dataset and caller record
    Try prefixing element keyword and check whether its throwing error when opening the form.
    If not, I would create one form method inside the form extension class which will return global variable buffer and call that form method inside DataSource extension.
    [Extensionof(formStr(ProdTableCreate))]
    final class ProdtableCreate_Extension
    {
         public PIDPackageRequestHeader  getPackageRequestHeader()
         {
             return packageRequestHeader;
         }
    }
    Inside the DataSource extension class you can get the formRun and call the above method.
    FormRun frun = this.formRun();
    pidProdTable.PackagingRequest = frun.getPackageRequestHeader().PackagingRequest;
     
    Thanks,
    Girish S.
  • Verified answer
    Martin Dráb Profile Picture
    237,970 Most Valuable Professional on at
    Refer to the object whether the variable is defined. It's the form, not the data source, so use element.packageRequestHeader when referring to it from the data source extension.

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
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans