XMLPort Generator

Recently, I need to import some flat text files into NAV into completely new tables. So first, I created a table containing all the fields in the correct order. Next I had to create an XMLPort to import the values. But, there were over 200 fields in my newly created table, and had 3 more tables with the same thing.

So, I created a little tool in .NET to read my table export and generate my XMLPort for me.

Feel free to use the tool if you have any use for it šŸ™‚

A few bullet points:

– export your table to text and put it in the right column
– XMLPort is always import, of type variable text (no xml)
– if you don’t supply anything in the fields, it will create an xmlport of type variable text to your source table.
– XMLPort name is by default set to “IMPORT %1” with %1 being the source table name


Oh, if you are interested, here is the source code.

Version: 1.2
6.9 KiB

12 thoughts on “XMLPort Generator

  1. Great tool…thanks for posting

    I ran into a problem with the fields window due to size of the table (even deleting code) default value 32767. I downloaded the GIT project, updated the MaxLength to unlimited (0) but ran into an issue where there is was issue with the generated xmlport code not stripping spaces from the tags.

    Does the GIT project version (3/30) correspond to the executable from 4/7? or does the generatexml function need updating to handle the increased size of the String Array?

    • Hello Alan,

      The Github should contain my latest version. My table were fairly large, but I never ran into a problem with it being too large.
      The tool should also work with just copying the fields and pasting that into the tool.

      If you still run into problems, maybe you could check into the solution above of Martin.

  2. Pingback: ArcherPoint Dynamics NAV Developer Digest - vol 85 - Microsoft Dynamics NAV Community

  3. Hello Magno,

    I just used it for a Nav16 XmlPOrt. I just change some small things :
    – as Alan, I updated the MaxLength to 0 to allow big text string
    – I added a function “EncodeTagName” to replace space, -, ., / and % for the Tag Name Property

    It work perfectly and save my time! I can sen it to you back if needed.

    Have a nice day.

    • Hi Julien,

      Apparently, the tagname I already created, but the change never got pushed to github.
      The textboxes are now also set to unlimited.

      This time, I updated the version to download here to 1.1 as well.

  4. Hi,

    great Tool, helps me to create bigXMLPorts. Thanks a lot.
    But, I have one suggestion.
    With exporting my table into a textfile, I also get all the FlowFilter und FlowFields exported.
    If I copy this textfile into your tool und create the XMLPort, I also get entries for these type of fields.
    I think it is better to ignore these fields when you create the XMLPort.

    Best regards

  5. Hi,

    I forgot the BLOB-Fields.
    I am not sure if it make sense to create an XMLPort entry for these fields, too.

    Best regards.

      • Hi Magno,

        I run into a little problem with the new modification.
        I have a Navision 2016 with a FoodVision AddOn.
        Foodvision installed lots of fields with long fieldnames (25-30 Charakters) into the tables.
        With exporting these tables as a textfile, the fieldclass-definiton sometimes appears in a new line (not in the same line like fieldname and datatype)!

        I am not very familiar with .Net, but I tried to modify your source.
        The result looks good šŸ™‚

        Here is my modification in the GenerateXMLPort-Function ….

        bool FieldsStarted = false;
        int lineindex = -1; // VG 17.07.2017

        // loop fields
        foreach (string line in txtFields.Lines)
        lineindex += 1; // VG 17.07.2017

        if ((FieldsStarted) && (line.StartsWith(” {“)))
        string[] Values = line.Split(‘;’);
        // VG 17.07.2017: If Datatype is BLOB, do not import into XMLPort
        if (! line.ToUpper().Contains(“BLOB”))
        // VG 17.07.2017: Caution: If fieldnames are to long, Datatype-Information (=Values[4]) are not in the same line!
        if (Values[4].Length == 0)
        Values[4] = txtFields.Lines.GetValue(lineindex+1).ToString().Trim(); // get next line
        // VG 17.07.2017: If Datatype is FlowField or FlowFilter, do not import into XMLPort
        if (! Values[4].ToUpper().Contains(“FLOW”))
        //if (!(line.ToUpper().Contains(“FLOW”) || line.ToUpper().Contains(“BLOB”)))
        sb.AppendLine(” { [” + GenerateGuid() + “];2 ;” + Values[2].PrepareForXMLField() + “;Element ;Field ;”);
        sb.AppendLine(” DataType=” + new string(Values[3].Where(c => c > ‘A’ && c < 'z').ToArray()) + ";");
        sb.AppendLine(" SourceField=" + txtSourceTableName.Text + "::" + Values[2].TrimEnd() + " }");
        } // VG 17.07.2017

        Best regards

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.