Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Run a class when a file is created in a folder

Posted on by Microsoft Employee

How is it possible to make a function in Ax 4.0 that will monitor a local Windows folder and run a class when a new file is detected inside this folder?

I'm unable to find anything that will guide me in the right direction, using Google and forum searches, when it comes to X++ and in particular the older Ax 4.0 my customer is running.

Background for this issue is that we recieve a xml file from a web front end and need to create a quotation based on this file. The class reading the xml file and creating a quotation is already up and running in Ax 4.0, but for now I need to manually trigger the class to run.

*This post is locked for comments

  • Martin Dráb Profile Picture
    Martin Dráb 230,198 Most Valuable Professional on at
    RE: Run a class when a file is created in a folder

    If you can use neither a batch nor a synchronous call and you need to stick to your original requirement, the solution is using FileSystemWatcher. It raises Created event when a file is created in the given folder. You'll a ,NET class library wrapping FileSystemWatcher, because you can't subscribe to events from X++, but I think you'll be able to use the library directly from AX process (via CLR Interop).

  • Vilmos Kintera Profile Picture
    Vilmos Kintera 46,149 on at
    RE: Run a class when a file is created in a folder

    This is exactly what my recommendation above is, to use BC from either their web app straight, or from a standalone service.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Run a class when a file is created in a folder

    Hi Vilmos

    Thank you for your suggestion. Crispin suggested much the same and in fact that was my first choice, to have the application that delivers the file also starts a method in our Ax class. However I'm unsuccessfull about logging in to Ax from the C# service that we are going to run on the Ax server.

    To run a batch job every minute or so is not satisfactory for our client. We have a web front end that awaits feedback and we want to avoid any delays. I'm going back to the track of having our service start the method and will post a new question when I have some solid info on where my code fails.

    Thanks a lot to both of you.

    Regards

    Bredo

  • Suggested answer
    Vilmos Kintera Profile Picture
    Vilmos Kintera 46,149 on at
    RE: Run a class when a file is created in a folder

    You could do it via a batch like mentioned above, but that is only one option.

    You could write a simple Service application which runs in the background in Visual Studio, that monitors if the file is received, and then makes a call to AX via Business Connector through a static method in your class, that initiates the processing.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Run a class when a file is created in a folder

    Thank you for the respons. I might have searched using the wrong keywords. I'll give it a try by using a recurring batch job with a high frequency.

    Regards

    Bredo

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans