Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

How to call private function in class?

(0) ShareShare
ReportReport
Posted on by 508
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.
 
 
  • Ken Manhattan Profile Picture
    Ken Manhattan 508 on at
    How to call private function in class?
    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.
  • Verified answer
    MuthukumaranAX Profile Picture
    MuthukumaranAX 2,901 on at
    How to call private function in class?
    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 
  • Martin Dráb Profile Picture
    Martin Dráb 230,371 Most Valuable Professional on at
    How to call private function in class?
    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.
  • Ken Manhattan Profile Picture
    Ken Manhattan 508 on at
    How to call private function in class?
    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
  • Suggested answer
    Waed Ayyad Profile Picture
    Waed Ayyad 6,493 Super User 2024 Season 2 on at
    How to call private function in class?
    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
     

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,642 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans