Setup All the Things
Setup data is one of the hardest things to keep strait in Dynamics NAV. If you have multiple developers on the same database, they might be modifying setup data to develop new features or testing for bugs. When you have setup data being changed constantly, you may not know what the correct setup is for your production system when it is time to push up your new code from the dev or QA system. To solve this issue, you can use XML Ports. XML Ports are a very handy way to export your data from one system to another. They can also be used to save the state of your system. The only issue with these ports is that you might not know which one is the most up-to-date. Specifically when you start using source control, it can become difficult to tell when you use XML data you just pulled, to use just yours that you modified, or a combination of both. The main issue is that the XML data files lose their original date created when you start pulling them in with source control. Our team needed a way to keep track of data and know when each port was created.
Comment Your Data
Our solution was comments. You can put in XML comments anywhere in the XML data and the ports do not care when they are ran. So we put a comment at the very end that has the date and time of the export.
IF Object.FINDSET THEN
FileName := 'C:\Repos\Foundation\Trunk\data\dat' + FORMAT(Object.ID) + '.xml';
EndLine := 10;
EndLine := 13;
XMLFile.WriteMode := true;
XMLFile.SEEK(XMLFile.LEN); //set position in file to the end
XMLFile.Write(FORMAT(EndLine) + FORMAT(EndLine) + '<!--DateCreated=' + FORMAT(TODAY) + FORMAT(TIME) + '-->');
UNTIL Object.NEXT = 0;
Going through the code snip-it above. We grab and loop through a few XML Ports that we want to run. We need to set what our export file path will be and we need to create a new line variable so we can properly output out comment on the next line in the XML data. Once we have exported the data, we reopen the file, seek to the end, and add our little comment.
<!--DateCreated=29/09/15 1:40:33 PM-->
Here are the last few lines of the XML data. You can really put the comment where ever you want. Just as long as it is NOT the first line in the file. In this case its the last line outside of the root element.
If you run the same XML Port manually and import the data that was created with this code, you will notice everything works as it did. The comment doesn’t effect anything.
There really is no use in reading in the date when you are importing the data in NAV. It really only becomes useful when you are using it combination with source control or automatic daily builds. When you combine this with a build, it becomes very apparent which data to use after you pull in all new change sets for that day.
You dont have use comments for just a date-time stamp. You could use them for any meta data about the file or port you want to keep track of. You could put in the developers name or the database/service it was generated from.