Run external program with job queue

luninautluninaut Member Posts: 3
Hi,
we recently updated to NAV 2016. I am currently looking for a way to run an external program (Zip program with password encryption).
Please respect the following conditions:
- Transfer of parameters at called program
- Program should be executed by a job queue
- Program should always run on the server (so that you can restart the job queue entry manually, no installation of the program on all clients)

I've tried the dotNet type System.Diagnostics.Process.System so far, but when running on the job queue it comes to the error message that a client callback of the function is not supported (ProcessShell: = ProcessShell.Process;).
And with a 'Windows Script Host Object Model'.WshShell the program seems to be executed only on the client computer.

Maybe someone else has an idea how to implement such a constellation under the 3-tier architecture. I'm grateful for every hint.

Best Answer

  • luninautluninaut Member Posts: 3
    Answer ✓
    Finally we got the solution. The missing hint was, that we had to set the property RunOnClient=No for the ProcessShell variable.

Answers

  • AlexDenAlexDen Member Posts: 86
    edited 2018-07-30
    Hi.

    You can run an external program by the following code:
    ProcessShell.Start(FileName,Arguments)
    
  • luninautluninaut Member Posts: 3
    Thank you for your answer. I already tried following code.
    ProcessShell := ProcessShell.Process;
    ProcessShell.StartInfo.UseShellExecute := FALSE;
    ProcessShell.StartInfo.FileName := Path.Path + '7z';
    ProcessShell.StartInfo.Arguments := 'u -tzip -mem=AES256 -p' + Password + ' ' + ZipFileName + ' ' + FileToZip;  
    ProcessShell.StartInfo.CreateNoWindow := TRUE;
    ProcessShell.Start();
    ProcessShell.WaitForExit(600000);  
    CLEAR(ProcessShell);
    

    But the dubugger stops at the first line with error message "Client callbacks are not supported on Microsoft Dynamics NAV Business Web Services." when running the codeunit in a job queue.
    It runs fine when I start the codeunit manually.
  • luninautluninaut Member Posts: 3
    Answer ✓
    Finally we got the solution. The missing hint was, that we had to set the property RunOnClient=No for the ProcessShell variable.
  • cvanderpoelcvanderpoel Member Posts: 9
    Hi Luninaut,

    The property of ProcessShell variable is probably set to RunOnClient Yes. So in case of a webservice call you can define an other variable ProcessShell2 set To RunOnClient No.
    IF CURRENTCLIENTTYPE = CLIENTTYPE::SOAP THEN BEGIN
      ProcessShell2 := ProcessShell.Process;
      ProcessShell2.StartInfo.UseShellExecute := FALSE;
      ProcessShell2.StartInfo.FileName := Path.Path + '7z';
      ProcessShell2.StartInfo.Arguments := 'u -tzip -mem=AES256 -p' + Password + ' ' + ZipFileName + ' ' + FileToZip;  
      ProcessShell2.StartInfo.CreateNoWindow := TRUE;
      ProcessShell2.Start();
      ProcessShell2.WaitForExit(600000);  
      CLEAR(ProcessShell2);
    END ELSE BEGIN
      ProcessShell := ProcessShell.Process;
      ProcessShell.StartInfo.UseShellExecute := FALSE;
      ProcessShell.StartInfo.FileName := Path.Path + '7z';
      ProcessShell.StartInfo.Arguments := 'u -tzip -mem=AES256 -p' + Password + ' ' + ZipFileName + ' ' + FileToZip;  
      ProcessShell.StartInfo.CreateNoWindow := TRUE;
      ProcessShell.Start();
      ProcessShell.WaitForExit(600000);  
      CLEAR(ProcessShell);
    END;
    
  • RockWithNAVRockWithNAV Member Posts: 1,139
    Instead if coming to a conclusion like RunOnClient=No this works, I hope you too understood why it works. :smile:
Sign In or Register to comment.