As Luc van Vugt has posted in his blog, Importobjects and ExportObjects are no longer supported in C/Side code. Because we used this command in many of our development tools I've been looking for an answer for this problem.
First, on the MSDN library, I read the following document: http://msdn.microsoft.com/en-us/library/hh166064%28v=nav.70%29.aspx
In here it states that you can use export objects by using the command line for the FinSQL.exe
OK, that was the first step for me. But how am I going to run this command from RTC as we are not allowed to use the SHELL command anymore?
Well, this is how I solved it:
First off all, I created a new codeunit witthe function:
Export Object(VAR Obj : Record Object;Format : 'txt,fob')
In this function I created the following variable:
Name: startCmdDatatype: DotNetSubtype: System.Diagnostics.Process.'System, Version=184.108.40.206, Culture=neutral, PublicKeyToken=b77a5c561934e089'
Next it was just a matter of entering the following code (ok, I also use a setup table ):
//Exports the selected objects object by objectSetup.GET();Setup.TESTFIELD("FinSQL filename");Setup.TESTFIELD("Workspace location");Setup.TESTFIELD("Server Name");Setup.TESTFIELD("Database Name");
CommandText := 'command=exportobjects, file="%1", servername="%2", database="%3", '+ 'filter="Type=%4;ID=%5", ntauthentication=yes, logfile=C:\QueryExportLog.txt';
IF Obj.FINDSET THEN REPEAT startCmd.Start(Setup."FinSQL filename", STRSUBSTNO(CommandText, Setup."Server Name", Setup."Database Name", GetObjectFileName(Obj), Obj.Type, Obj.ID)); UNTIL Obj.NEXT = 0;
Of Course the import objects will probably work in a similar way.. and the system.diagnostics.process.start component can probably be used for a lot of other purposes too!
As some of you may know Luc van Vugt and I work closely together and when we discussed my draft version of this blog, he mentioned that Ron van de Wijngaard (ToIncrease) had sent him a piece of example code which would do the same. Ron said that Luc could use it in one of his future posts, but since I was already working on this one he gladly left me the honors. It was great to find out dat Ron also is using the same DotNet components as myself. So this would be a matter of 'great minds think alike'
- Edit 10-03-2012 - I just added a simplified example of the export function as a text file to this post.
I try to add comments but nothing appear...
Is this solution acceptable for NAV2009?