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

Access variable across different CoCs of the form

(0) ShareShare
ReportReport
Posted on by 70

Hi,

My requirement is to access variable initialized in a CoC in another CoC.

I have a CoC of Form init() method. In this method I have declared and initialized  a variable. I have another CoC of the form datasource method executeQuery(). 
Now I want to get the value of the variable from the CoC of init() method.

Can anyone help me on how to access variable of init() method CoC in executeQuery() method CoC

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    If you declare a variable inside a method (such as init) it's visible only in init method. CoC doesn't change this fact. ExecuteQuery can't see any local variables of init method.

    You can add a form level variable, then it will work.

  • praneethkumar.d365 Profile Picture
    70 on at

    This is how my code is

    Init CoC

    [ExtensionOf(formStr(FormName))]
    final class FormName_Extension
    {
    int variable1;

    public void init()
    {
    next init();
    variable1 = 10;
    }

    }

    executeQuery CoC

    [ExtensionOf(formDatasourceStr(FormName, CustTable))]
    final class FormNameDS_Extension
    {
    public void executeQuery()
    {
    next executeQuery();
    //Need to access variable1 here
    }
    }

  • Verified answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    OK, so the variable is not in the init method CoC.

    You should be able to access it via element.variable1. If not, you can create a "getVariable1()" method in your first class and call that from the second class to get the variable.

  • praneethkumar.d365 Profile Picture
    70 on at

    I was not seeing the intellisense on typing 'element.' But when I copy pasted it worked.

    Thanks !

  • nmaenpaa Profile Picture
    101,162 Moderator on at

    IntelliSense is not always working very well with CoC, so it always makes sense to just "type and compile" and see if something 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

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
Martin Dráb Profile Picture

Martin Dráb 503 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans