Skip to main content
Dynamics 365 Community / Forums / Finance forum / How to call private fu...
Finance forum

How to call private function in class?

editSubscribe (0) ShareShare
Posted on by 382
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.
  • Ken Manhattan Profile Picture
    Ken Manhattan 382 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.
    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,893 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 222,703 Super User 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 382 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.

  • Suggested answer
    Waed Ayyad Profile Picture
    Waed Ayyad 2,023 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.
    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

Helpful resources

Quick Links

New Blog Features Released!

Check out the new community blog features for viewers and authors…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…


Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,166 Super User

Martin Dráb Profile Picture

Martin Dráb 222,703 Super User

nmaenpaa Profile Picture

nmaenpaa 101,138

Featured topics

Product updates

Dynamics 365 release plans