Skip to main content

Notifications

Microsoft Dynamics NAV (Archived)

best practice to run an external program from NAV codeunit

Posted on by 5,124

Hello experts! I was wondering if you can help guide me in trying to run an exe file (.net) I wrote from within NAV.  First of, where is the best place to store this exe file?  Should I store it in the APPLICATIONPATH\addins folder?  If so, does this mean I have to distribute this exe file in each RTC workstation?

Secondly, I am not sure if I am doing this correctly.  I am using System.Diagnostics.Process to run this program from within my codeunit.  see below.

....
CLEAR(process);
process := process.Process();
process.StartInfo.UseShellExecute := FALSE;
process.StartInfo.FileName := ConvertProgPath;
process.StartInfo.Arguments := InputXMLPath + ' -xsl ' +  XSLTPath + ' -output ' + OutputFilePath;
process.StartInfo.CreateNoWindow :=TRUE;
process.Start();

process.WaitForExit();  //tells Nav to wait for the program to close

But it doesn't seem to work.  I am erroring out.    it says it doesn't know where the file is.  I stored the exe file in the c:\program files\Microsoft dynamics nav\70\service\addins folder.  But when I check if it exists, it says it doesn't.  see below code snippet whereby it will error out.

  ConvertPDFPath := APPLICATIONPATH + 'addins';
  ConvertProgPath := ConvertPDFPath + '\myprogram.exe';

  IF File.EXISTS(ConvertProgPath) THEN
     message('%1 EXISTS!',ConvertProgPath)
  ELSE
     ERROR('%1 DOES NOT EXIST!',ConvertProgPath);

But If I run the program using the start-run (outside of nav) it works!

Thoughts?

*This post is locked for comments

  • Verified answer
    Andrey Baludin Profile Picture
    Andrey Baludin 3,941 on at
    RE: best practice to run an external program from NAV codeunit

    Hi!

    I use next construction, where Process is System.Diagnostics.Process dotnet variable:

    It's a codeunit which runs by job queue and takes file name and arguments from job queue entry parameter string (they separate by ; symbol). RunOnClient property of dotnet variable should be = No in this case.

    app2.JPG

    Also you can use universal function with path and attributes parameters for running any app:

    app2.JPG

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans