Skip to main content

PreImport Trigger

  • PreImport Trigger programs are executed during import operations before the platform logic for creating instances (e.g., users) begins.
  • These are used to modify the imported template data (rows and headers) to meet specific business requirements before it is processed by the platform.
  • The trigger is currently enabled for UserProfile type only.
  • Like other triggers, the PreImport Trigger can use services to get and update data as needed.

Execution Flow

  • When importing users, a PreImportTrigger is triggered after reading the template file rows but before creating any instances.
  • The trigger is executed from: Prorigo.Protrak.Services.Impl.Helpers.ExcelReader.csMethod: ReadTemplate(Stream stream)
  • This happens after headers and rows are read from the standard user template.
  • The trigger receives a List<Dictionary<string, string>> representing the template rows where each dictionary is a row with header-value pairs.

Coding Guidelines

  • PreImport Trigger program is a class that must implement the interface IPreImportTriggerProgramAsync

    public interface IPreImportTriggerProgramAsync
    {
    Task<List<Dictionary<string, string>>> RunAsync(List<Dictionary<string, string>> templateRows);
    }

    NOTE: Implement IPreImportTriggerProgramAsync with the RunAsync method to enable asynchronous, scalable trigger logic. Most internal service methods are now async, and their synchronous versions are deprecated and will be removed. Use RunAsync to ensure compatibility with these changes.

  • This method:

    • Receives: List of template rows (List<Dictionary<string, string>>)
    • Returns: Modified list of template rows to be used for further import processing. Save trigger under: Type => UserProfile => Triggers In the Type => Triggers section, PreImport Trigger will be available only for UserProfile for now.

Typical use cases for PreImport Trigger

  • Clean or normalize imported data (e.g., trimming whitespace, fixing capitalization).
  • Modify values based on custom business rules (e.g., converting role names to role IDs).
  • Sanitize sensitive or optional fields.

Anti-patterns / When Not to Use PreImport Trigger

  • Prefer configurations
  • This trigger should not raise errors directly —it only modifies data; validation failures should be handled using configurations.

Sample Code

using System;
using System.IO;
using System.Net;
using System.Linq;
using System.Data;
using System.Collections.Generic;
using Prorigo.Protrak.Programs;
using Prorigo.Protrak.API.Services;
using Prorigo.Protrak.API.Contracts;

namespace Prorigo.PreImportTriggerProgram
{
public class PreImportTriggerProgram : IPreImportTriggerProgram
{
public IInstanceService InstanceService { get; set; }
public IRelationService RelationService { get; set; }
public ITypeService TypeService { get; set; }
public IUserService UserService { get; set; }
public IFileService FileService { get; set; }
public INotificationService NotificationService { get; set; }
public ILifecycleService LifecycleService { get; set; }
public ILoggingService LoggingService { get; set; }

public List<Dictionary<string, string>> Run(List<Dictionary<string, string>> templateRows)
{
if (templateRows == null) return new List<Dictionary<string, string>>();

foreach (var row in templateRows)
{
foreach (var column in row)
{
var header = column.Key;
var value = column.Value;

// Example: Trim extra whitespace
row[header] = value?.Trim();
}
}

return templateRows;
}
}
}

Note: The Run method (from IPreImportTriggerProgram) should only be used if the trigger logic is fully synchronous, does not involve any service/API calls, and consists only lightweight in-memory operations.