Skip to main content

Notifications

Announcements

No record found.

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

What type of class for a utility or common class ?

(0) ShareShare
ReportReport
Posted on by 508
Hi everyone,
 
I want to create a common class or utility class that the purpose is to record some activity with its timestamp in a log table. So basically this utility class will be called in several of my other classes.
I created something like this:
class MyGlobalClass{    public static void insertToLog(str _classname, str _methodname, Notes _param)    {        MyLogTable   logTable;        System.DateTime localDateTime = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::getSystemDateTime(), DateTimeUtil::getUserPreferredTimeZone());                ttsbegin;                        logTable.clear();        logTable.ID = localDateTime.ToString('yyyyMdd_HHmmss');        logTable.ActionDate = DateTimeUtil::date(localDateTime);        logTable.ClassName = strFmt(/%1 - %2/, _classname, _methodname);        logTable.InputParameter =  _param;        logTable.insert();                ttscommit;    }}
 
I'm wonder if this is the correct way? 
And how to use this in my other class ? because currently, after successfully build, when I type this in the class that I wanted, the Intellisense didn't show this /MyGlobalClass/
Is there something wrong like the type of class ? 
 
Btw, why it is very hard now to put code in this thread with the new UI ? I'm choosing C++ for the language just now because there is no X++  :)
 
 
Thanks,
 
  • Ken Manhattan Profile Picture
    Ken Manhattan 508 on at
    What type of class for a utility or common class ?
    Yeah, Build again and restart Visual Studio done it. Thanks.
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,354 Most Valuable Professional on at
    What type of class for a utility or common class ?
    It looks fine to me. Check out if the call of MyGlobalClass::insertToLog(...) compiles correctly. If so, you have a problem with IntelliSense, not with visibility of the class. If not, make sure that you're using in the same module or that the module has a reference to the one containing MyGlobalClass. If that's all right, look at the error message provided by the compiler.
     
    If the class is supposed to contain static methods only, you can make the whole class static, to make it explicit.

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,622 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,354 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans