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 to call private function in class?

(0) ShareShare
ReportReport
Posted on by 552
Hi guys,
 
I'm creating a /global/ class and inside has a method with /public static str/ function, like this:
public static str logInbound(str _classname, str _methodname, Notes _param)    {        MyLogTable   logTable;        System.DateTime localDateTime = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::getSystemDateTime(), DateTimeUtil::getUserPreferredTimeZone());                ttsbegin;                        logTable.clear();        .        .               logTable.insert();                ttscommit;        return logTable.ID;    }}
 
Inside this class, I also create a private method like this:
 private str getNum (Notes _param)    {                <few logic>        return MyNum;    }
 
Question is how to use this private method inside the 1st method /LogInbound/ ? Because when I try to type /this. / no suggestion which I thought could show up that private method.
 
Thanks.
 
 
I have the same question (0)
  • Suggested answer
    Waed Ayyad Profile Picture
    9,039 Super User 2025 Season 2 on at
    Hi Ken,
     
    You can't call this inside the Static method,
    1- Try to make the private method static. I don't try it before but give it try.
    2- Define the MyNum as global variable and create static method to get its value, but I think you should call it on non-static method.
    3- Try to create new instance of the class on the logInbound method and call you private method on it.
     
     
    Thanks
    Waed Ayyad
     
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
     
  • Ken Manhattan Profile Picture
    552 on at
    Hi Waed,
     
    Sorry, a bit confuse. So you're meaning is :
    1. add static keyword in my private method, like this :
        
    private static str getNum (Notes _param)    
    {                
        <few logic>        
        return MyNum;    
    }
     
    2. So I need to declare variable str MyNum at the top, right after my class name, right ?
     
    3. This is quite confuse. for example the class name is MyGlobalClass, so inside my logInbound() method, I should write something like : MyGlobalClass    globalClass = New MyGlobalClass:;construct(), and then from this variable globalClass, I'm calling the getNum() method and put into variable MyNum.
     
    Is my understanding correct ?

    PS: So basically, I'm creating this global class, gonna be called with my other classes, calling that logInbound method. But that private str getNum() method that I put inside the global class, will be used only inside that logInbound.

     
    Thanks
  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at
    In short, and instance (non-static) method needs an instance, therefore either you'll keep your method non-static and create an instance to call the method on, or you'll make the method static.
     
    Don't create any class-level variable; that would be another topic.
  • Verified answer
    MuthukumaranAX Profile Picture
    2,903 on at
    private method (getNum) is not showing in LogInbound method because it is static method... if you remove static keyword then you will be able to access private method using this operator.
     
    Otherwise, initialize a variable for the class and using the initialized variable you can access the private method 
  • Ken Manhattan Profile Picture
    552 on at
    Hi all,
     
    Thanks. I removed the static keyword. And add new instance of the class in LogInBound method. It works, the private method appeared.
    Solved.
     
    I want to mark it as solved to all, however it loading forever still. I guess the bugs not yet fixed.
     
    Thanks again.

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 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans