lunedì 10 settembre 2012

Iron Speed Import

I noticed there's a little issue in Iron Speed importing process.
When you try to import a csv file and a column has a foreign key to a filed table having  Dispay As attribute compose by more then one column of the linked table, the import process fail, or try to create a new record in the linked table even if the record exists.

An example could make the situation clear:
tables: userInfo, projects
fk: projects.user_id -> userInfo.user_id
projects.user_id has the following display as expression: userInfo.serialCode+ " " + userIndo.Name

In other words the method GetDFKA in ImportDataItems can't translate the imported column to the corredponding primary key beacuse of the expression on Display as.

I found a little workaround, changing a bit the code of GetDFK, so the methos return the first valid column found.
For me it works because my first field was the one that is present in the cvs to import.

The code:

 public static string GetDFKA(ForeignKey fkColumn)
        {
            bool isDFKA = false;
            if (fkColumn == null) {
                return null;
            }
            string _DFKA = fkColumn.PrimaryKeyDisplayColumns;

            // if the formula is in the format of "= <Primary table>.<Field name>, then pull out the data from the rec object instead of doing formula evaluation
            string tableCodeName = fkColumn.PrimaryKeyTableDefinition.TableCodeName;
            string column = _DFKA.Trim('=').Trim();
            if (column.StartsWith(tableCodeName + ".", StringComparison.InvariantCultureIgnoreCase)) {
                //column = column.Substring(tableCodeName.Length + 1);
               
               
            }
            int pos = -1;
            foreach (BaseColumn c in fkColumn.PrimaryKeyTableDefinition.Columns)
            {
                int currPos=column.ToLower().IndexOf(tableCodeName + "."+c.CodeName);
                if (currPos>=0)
                {
                    isDFKA = true;
                    if (pos==-1 || currPos < pos)
                    {
                        column = c.CodeName;
                        pos = currPos;
                    }
                    //break;
                }
            }

            /*
            foreach (BaseColumn c in fkColumn.PrimaryKeyTableDefinition.Columns) {
            if (column == c.CodeName) {
                isDFKA = true;
                break;
                }
            }
             */

            if (isDFKA) {
                return column;
            } else {
                return null;
            }
        }

Nessun commento:

Posta un commento