How to import CSV files data into a collection

<< Click to Display Table of Contents >>

Navigation:  Bizagi Studio > How To´s > Useful how-to's >

How to import CSV files data into a collection



Bizagi allows users to import CSV files (comma-separated values) to use its data in collections. This type of files are very common in spreadsheet apps and therefore, having the option to import them to a collection is very useful. Follow these steps to import CSV files.


Before you start

Make sure your files are a CSV file. CSV UTF-8, CSV (Macintosh) and CSV (MS-DOS) are not supported.


Import a CSV file data into a Collection


To import the CSV file, it is necessary to create an expression. This expression uses an uploaded file (in this case the CSV file) and takes its values to assign them into different columns of a collection. See the following example:


1.On the step 4. Business rules of the Process wizard, create the following expression on the option Activity actions:


var ImportedCSVFile = Me.getXPath("InvoiceProcess.CSVFile");

// This file verifies the existence of 1 imported file.

if(ImportedCSVFile.size() > 0){

      // This code is made for 1 file only

      var Data = ImportedCSVFile.get(0).getXPath("Data");


      var characters=Data.Length;

      var text = "";

      for(var i=0; i<characters;i++)


             text = text + Convert.ToChar(Data(i));



      var n = text.IndexOf("\n");

      while (n >=0) {

             var j = text.IndexOf(",");

             if (j>0) {

                    var element1 = text.Substring(0, j);

                    var element2 = text.Substring(j+1, n-j-1);

                    var i2 = element2.IndexOf(",");

                    var element3 = element2.Substring(i2+1, element2.Length-i2-1);

                    element2 = element2.Substring(0, i2);


                    var NewInvoice = Me.newCollectionItem ("InvoiceProcess.Invoice");





             text = text.Substring(n+1);

             n = text.IndexOf("\n");




Consider the following parameters when building the expression for your own process:


Bold text of the code: InvoiceProcess.CSVFile is the attribute you create to upload a document, in this case, the .csv file. Therefore its name has to match with the name of your attribute.


Bold text of the code: var NewInvoice = Me.newCollectionItem ("InvoiceProcess.Invoice") This is the XPath of the entity in which you load the data from the csv file. Therefore its name has to match with the name of your entity.


Bold text of the code: NewInvoice.setXPath("Name",element1) Name1 and text1 are the column header and its corresponding row data.