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 :
Microsoft Dynamics AX (Archived)

Can the Tools->Caches->Refresh Be done in code?

(0) ShareShare
ReportReport
Posted on by 2,145

Can the

Refresh Dictionary

Refresh Data

Refresh Elements

Be done in an x++ job?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    Yes - they're just menu items.

    static void mcaClearCaches(Args _args)

    {// mca jeb 27Sep2013

       Args        args;

       args = new args();

       args.name(identifierStr(SysFlushAOD));

       new MenuFunction(menuitemActionStr(SysFlushAOD), MenuItemType::Action).run(args);

       args = new args();

       args.name(identifierStr(SysFlushData));

       new MenuFunction(menuitemActionStr(SysFlushData), MenuItemType::Action).run(args);

       info(strFmt("Flushed data"));

       args = new args();

       args.name(identifierStr(SysFlushDictionary));

       new MenuFunction(menuitemActionStr(SysFlushDictionary), MenuItemType::Action).run(args);

    }

    Janet

  • Suggested answer
    Brandon Wiese Profile Picture
    17,788 on at

    Be careful which tier (client/server) you are calling those SysFlush methods on.  They work differently depending on the tier, and despite documentation to the contrary the flush does not always get communicated to other AOS (in a cluster, for example).

    Running SysFlush on the client tier is basically the same as closing and re-opening the client, and will not solve issues related to a stale server cache.  It also does not delete the AUC files, but there are other methods that do purge the AUC files in real time.

  • Community Member Profile Picture
    on at

    Great points; thanks, Brandon!

  • dolee Profile Picture
    11,279 on at

    Another option would be to call the SysFlushXXX classes directly.

    // adding "client" or "server" to the static method declaration to force where the refresh runs

    public static void FlushAll()

    {

       Args args;

       // Leave the "args" as null will skip the info messages normally shown when using menu items.

       SysFlushAOD::main(args);

       SysFlushData::main(args);

       SysFlushDictionary::main(args);

    }

  • bRadlyJames Profile Picture
    2,145 on at

    So, when you click the actual menu items, where do they run?  Server or Client?

  • Alex Kwitny Profile Picture
    395 on at

    It depends, since it's "called from".  Throw an info log on there if you want to tinker and see:

    info(strfmt("Running on server? %1", Global::isRunningOnServer()));

  • Suggested answer
    Brandon Wiese Profile Picture
    17,788 on at

    When you click the menu items from the Tools->Caches menu from the client interface, they run on the client.  This tends to be pretty pointless, since you can just as easily close and re-open the client.  Where you really NEED to clear caches is on the server, especially in a cluster environment where changes made on one AOS may not be seen on the other until midnight when all AOS flush their cache on schedule.  In my environments those menu items are set to Server and we use them frequently to avoid having a mass AOS restart when making parameter and changes to records in tables that are cached Entire table.

  • Mazherullah Profile Picture
    345 on at

    Hi Lee,

    Regarding your below solution.  May I know how to add "Client" or "Server" to the static method declaration to force where the refresh runs.

    Also, what these commands do.  Just they clear the cache ???

    regards

    ~~~~

    Another option would be to call the SysFlushXXX classes directly.

    // adding "client" or "server" to the static method declaration to force where the refresh runs

    public static void FlushAll()

    {

       Args args;

       // Leave the "args" as null will skip the info messages normally shown when using menu items.

       SysFlushAOD::main(args);

       SysFlushData::main(args);

       SysFlushDictionary::main(args);

  • Suggested answer
    Chaitan Profile Picture
    50 on at

    It is fine to execute from the AOT Menu, the action is different from running the job executing "main(args)". Brandon covered the explanation.

    It is OK to test this Job in a DEV standalone box for understanding and educational purpose. There is a mixture of calls that hits both server and client when you execute the job.  Copy the above code for testing as Alex suggested into all the system classes methods and it will tell you with the Infolog msg. Don't forget to remove the code later-on.

    But never run the job particularly in High Availability/Clustered environments.

       SysFlushAOD::main(args); // Avoid calling this main method directly in Multi-AOS environments.

       SysFlushData::main(args); 

       SysFlushDictionary::main(args);  // Refreshes few elements which are (enumeration types, EDT, classes, tables, configuration keys, license codes & security keys).

    We have seen adverse effects in the past while one of our colleague introduced this job in Prod and executed it while other users accessing the instance faced nasty temp errors. This was probably 3 yrs ago.

    I proved that it was causing harm and forced them remove that code and reboot AOS to recover from errors, Since it cleared Server side Cache while client AX32.exe has no idea as the references were still pointing to records cached on Server side. 

    Hope the explanation helps.

  • Suggested answer
    Alex Kwitny Profile Picture
    395 on at

    Here is a better job that should clear both the client and server caches:

    static void AKWRefreshCaches(Args _args)
    {
        void runClientServer(str _actionMenuStr)
        {
            MenuFunction        mf;
    
            mf = new MenuFunction(_actionMenuStr, MenuItemType::Action);
            mf.run();
    
            mf = new MenuFunction(_actionMenuStr, MenuItemType::Action);
            mf.runOn(ClassRunMode::Server);
            mf.run();
        }
    
        runClientServer(menuitemActionStr(SysFlushAOD));
        runClientServer(menuitemActionStr(SysFlushData));
        runClientServer(menuitemActionStr(SysFlushDictionary));
        runClientServer(menuitemActionStr(SysFlushReportServer));
    
        info("Done");
    }


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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans