If you're familiar with the default TIF tool that comes out-of-the box from Microsoft, and you've been working with it quite some time .. you definitely started to wonder how you can make things faster or easier … how you can automate some "actions", like exporting and importing objects. Exactly this we (at my office) were investigating on how we could automate this.
A while ago, we were looking for a good solution for "making the TIF Tool a little bit more easy". We were looking for a way to export and import objects automagically. And apparently, there are some new possibilities in C/SIDE to do that.
There are two new instructions: IMPORTOBJECTS and EXPORTOBJECTS. You can find them in the symbol menu in SYSTEM/Object/…:
This feature is really undocumented .. In the way that I really can't find any documentation whatsoever of it. So please don't mind the mistakes or misinterpretations that might come up in this article… .
The EXPORTOBJECTS-statement has got three parameters:
So, no fob file! If you try another integer (e.g. "2"), you get an error that explains that there are only two supported formats:
As you can see, it's very straight forward. If you want to export all modified objects, you could write something like:
recObject.SETRANGE(Modified,TRUE); EXPORTOBJECTS('C:\==WORKINGFOLDER\Temp\Objects_Format_0.txt',recObject,0); //txt EXPORTOBJECTS('C:\==WORKINGFOLDER\Temp\Objects_Format_1.xml',recObject,1); //xml
Easy, isn't it? With this code, I'm exporting to both text and xml. Does it need more explanation? I think not .
For importing objects, you need the IMPORTOBJECTS-statement, which has got only two parameters:
Importing a file is nothing more then calling the statement:
IMPORTOBJECTS('c:\MyFile.txt',0); //import a textfileIMPORTOBJECTS('c:\MyFile.xml',1); //import a xml-file
Why isn't my table exporting to xml?
When you export to xml, you notice that not all objects are exported. Only Forms and Reports are exported to XML. When you try it by hand (File/Export), you actually notice the same thing. Try to export a table to xml … you'll notice it just creates an empty xml-file.
You might wonder why this is. Well, obviously (and this is just a guess) the export-to-xml option was primarily developed to support the transformation (FORM and REPORT transformation).
Why would this be useful?
I have seen a number of threads on Mibuso and DynamicsUser where people want to be able to import/export objects, so I know there are some of you that will be quite glad :-). If I think of it, I can imagine people see some possibilities in some kind of "version management" system, to keep track of the changes per object. Furthermore, there is may be a possibility to "Fetch" objects from a customer and import it in a dev-environment … or the other way around?
The combination of these statements with some possibilities you have in the object table (changing version list, modified-flag,…), or web services in NAV 2009 (sending/receiving objects to/from a customer or other), or… can lead to creative development tools if you ask me :-). Ideas are always welcome! Post them as a comment .
Are there other things to think about?
Well, the only thing I could think of (at the moment) is the fact that these statements don't work in the RTC (RoleTailored Client). You'll get this error message:
Does it matter? As long as the development environment is in the Classic, I don't think it will matter. It
only matters when you want to combine it with Web Services. That runs on the service tier, which means that importing or exporting the objects won't work through web services process. You'll need to include a NAS to do that … and that makes things a little bit more complicated.
That was it. Enjoy!
Nice article. You can also use "Blob Reference" field in Object system table for exporting objects. This solution works also works in previous NAV versions.
I would have expected to have fob-import/export... .
Nice. I guess I'm not the only one that wanted to automated the transformation for forms to pages. It's good to know these new commands are coming up - but without a compile option, the import is a bit useless don't you think?
You're right. I forgot to mention that these statements became available in NAV 2009 Sp1, which will be available in the near future... . I changed my title ...
I am not able to find the OBJECTS in SYSTEM.
i am in NAV 2009 classic version...
about which version you are talking....