NAV2013 - ExportObjects from RTC

Problem?

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?

Solution!

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: startCmd
Datatype: DotNet
Subtype: System.Diagnostics.Process.'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

Next it was just a matter of entering the following code (ok, I also use a setup table Wink):

//Exports the selected objects object by object
Setup.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!

Other solutions available.

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' Big Smile

- Edit 10-03-2012 - I just added a simplified example of the export function as a text file to this post.

Comment List
  • Hi Marco,

    One addition: in my piece of code I used the current context to determine the finsql executable. As a result you don't need the setup table and it works out of the box.

    Have you seen my piece of code? If you want I can send it to you.

    Regards,

    Ron

  • Hi Ron,

    First of all, thanks for the input you gave us!

    I've seen your code but decided not to 'borrow' it in this blog because it was nog originally my own code. I must say it is indeed a great thought of using the CustomConfig settings to retrieve the server, database and instances name.

    My code was still in a proof of concept phase at this point.  

  • Marco, I put this into the 2013 Development Environment, but System.Diagnostics.Process is not in my Assembly List. Where does that come from?

  • Hi Dave,

    Sorry for my late reaction but I was recovering from surgery. Just go to "System" in the Assembly list in NAV. Then you will find "System.Diagnostics.Process" in the "Type" fields.

  • Hi Marco,

    I try to repeat this solution, but when I run Export Object Function error is appeared 'The DotNet variable has not been instantiated'.

    What have I do else?

  • Hi Olga,

    First of all, dit you set the "RunOnClient" property on the startCmd variable to 'yes'? If not, that could be the problem of your error.

    I also added a file to to the blog post with a simplified example (ExampleExport.txt) which you can use.

    dynamicsuser.net/.../ExportExample.txt

    I hope this will solve your error! If not, just let me know!

  • Unfortunately,

    setting the "RunOnClient" property on the startCmd variable to 'yes' didn't solve my problem.

    I also import your CU and run it from page but error is appeared again.

  • Hi Olga, that is strange.. is it possible for you to send me your code so I could test it on my machine?

    Just to be sure, I'm working on NAV2013 RTM on Win7.

  • Hi Marco,

    maybe I have this issue because I try to implement it in NAV2009 and not in NAV2013...

  • Hi Marco,

    I try to add comments but nothing appear...

    Is this solution acceptable for NAV2009?

  • Hi Olga,

    Since you're a visitor, your comments do not automaticly appear on my blog. I have to publish them manually. I would advice you to create an account for dynamicsuser.net

    My example was only tested on NAV2013. On NAV2009 it will not work and because we have the "EXPORTOBJECTS" function in C/AL which is a lot simpler to use, this workaround is nog neccesary.

    In NAV2009 you can just use something like this:

         LocalObject.RESET;

         IF LocalObject.GET(Type, '', ID) THEN BEGIN

           LocalObject.SETRANGE(Type, Type);

           LocalObject.SETRANGE("Company Name", '');

           LocalObject.SETRANGE(ID, ID);

           EXPORTOBJECTS(GetObjectFileName(LocalObject), LocalObject, 0);

         END;

  • Hi Marco,

    thank you!

    EXPORTOBJECT Function is may be used only in CC and I need it in RTC. And in RTC it unsupported

  • Hi Olga,

    I tried it too in NAV2009 but unfortunately the FinSQL.exe in NAV2009(R2) does not support the "command" parameter. So I'm afraid it's nog possible in the NAV2009 RTC. :(

  • Hi Marco,

    thank you for you help!

    So, will be waiting for upgrade... :(

  • Hi Olga,

    You're welcome, too bad I couldn't solve your challenge.

Related
Recommended