How to Make a Pre-Process Import Data Function That Drops Extra Characters

book

Article ID: 178796

calendar_today

Updated On:

Products

CMDB Solution

Issue/Introduction

 

Resolution

When creating a Datasource for an Import/Export Rule the Pre-process import data option can be used to impose a character limit on the imported data. The following function provides an example where data from the "departmentnumber" column is limited to six characters:

  /*
    This sample demonstrates how to iterate through the data from
    the foreign data source and perform some standard operations.
  */
  // Check that the required columns exist.
  if (!importData.Columns.Contains("departmentnumber"))
    throw new Exception ("This function expects column 'departmentnumber’.");
  // Iterate through all rows
  for (int i = 0; i < importData.Rows.Count; i++)
  {
    DataRow row = importData.Rows[i];
    if (row["departmentnumber "] != System.DBNull.Value)
    {
        string departmentNumber = (string)row["departmentnumber"];
        row["departmentnumber"] = departmentNumber.Substring(0, 6);
     }
  }
  return importData;

 

To use this function for a column with a different name simply replace all the intances of "departmentnumber" with the appropriate column name. If datasource is an LDAP datasource it is not necessary to move the column name to the Use these columns in pre-processing function: box.