PowerShellRunner := PowerShellRunner.CreateInSandbox; PowerShellRunner.WriteEventOnError := TRUE; PowerShellRunner.ImportModule('C:\Commandlets\cmdletExport.ps1'); PowerShellRunner.AddCommand('Export-NAVApplicationObjectFile'); PowerShellRunner.AddParameter('Database','NAV2016PL'); PowerShellRunner.AddParameter('WorkingFolder','D:\'); PowerShellRunner.AddParameter('ExportFile','CU1.txt'); PowerShellRunner.AddParameter('Filter','Type=Codeunit;ID=1'); PowerShellRunner.AddParameter('Verbose'); PowerShellRunner.BeginInvoke; REPEAT SLEEP(1000); UNTIL PowerShellRunner.IsCompleted;
Answers
https://msdn.microsoft.com/en-us/library/system.management.automation.powershell(v=vs.85).aspx
Let the forum know how you get on.
I should add that the use of .net in NAV will be limited in the future therefore you may go down a route that is not futureproof with this approach.
https://blogs.msdn.microsoft.com/nav/2015/12/21/coffee-break-use-the-powershell-runner-add-in/
But you can do it with any NAV Version, even 2.x . For NAV 2009 I provided some sample objects on how to do this here:
http://www.msdynamics.de/viewtopic.php?f=17&t=28159
My code is as follows:
I even added a long sleep period so the runner won't close
The DotNet variable is RunOnClient: No, since when i try to set that to true, NAV returns an error saying that it cannot find the file and it's dependencies (the PowerShellRunner file)
Here's the code:
The commandlet i used instead of the one NAV provides is this one:
http://www.waldo.be/2014/06/04/nav-2013-r2-export-objects-with-powershell-3/
The PowerShellRunner works on client (DotNet variable), and the sleep after the Invoke makes sure nav doesn't close the PowerShell before it finishes the entire script
I appreciate every tip, you were all a great help and i hope this will help everyone with a similar problem
https://msdn.microsoft.com/en-us/library/dd338733(v=nav.90).aspx
i am trying with same code on my local system where service is installed but could not export object file with no error. can't figure out what i am doing wrong.
i am checking event viewer also but no error message there. i am using same code as above.
can you please help out? Thanks,
REPEAT
SLEEP(1000);
UNTIL PowerShellRunner.IsCompleted;