Skip to main content

Notifications

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 85
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.
 
  • Verified answer
    Martin Dráb Profile Picture
    232,866 Most Valuable Professional on at
    How we can access the global variable/method declared at form extension class
    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.
  • Verified answer
    GirishS Profile Picture
    27,825 Moderator on at
    How we can access the global variable/method declared at form extension class
    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.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,118 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,866 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans