TrackStudio Enterprise 3.5
Example 3

The following script shows how several linked objects are imported. This script imports tasks and if there is no user with the task handler's name in the system, the script creates a user with the specified name:

Collection list = new ArrayList();

Map taskMap = new HashMap();
taskMap.put(CSVImport.TASK_NAME, inputMap.get("Name"));
taskMap.put(CSVImport.TASK_CATEGORY_ID, CSVImport.findCategoryIdByName((String)
inputMap.get("Category")));
list.add(taskMap);

String msgHandlerName = (String) inputMap.get("Message Handler");
String msgHandlerId = null;
Map userMap = new HashMap();
if (msgHandlerName != null && msgHandlerName.length() != 0) {
   msgHandlerId = CSVImport.findUserIdByName(msgHandlerName);
   if (msgHandlerId == null) {
       userMap.put(CSVImport.OBJECT_TYPE, CSVImport.USER_TYPE);
       userMap.put(CSVImport.USER_NAME, msgHandlerName);
       userMap.put(CSVImport.USER_LOGIN, msgHandlerName);
       userMap.put(CSVImport.USER_PRSTATUS_ID,
            CSVImport.findUserStatusIdByName("administrator"));
       userMap.put(CSVImport.USER_COMPANY, "Co.");
       list.add(userMap);
   }
}

Map messageMap = new HashMap();
messageMap.put(CSVImport.OBJECT_TYPE, CSVImport.MESSAGE_TYPE);
messageMap.put(CSVImport.MESSAGE_TASK_ID, taskMap);
if(msgHandlerId != null )
    messageMap.put(CSVImport.MESSAGE_HANDLER_USER_ID, msgHandlerId);
else
    messageMap.put(CSVImport.MESSAGE_HANDLER_USER_ID, userMap);
messageMap.put(CSVImport.MESSAGE_MESSAGE_TYPE_ID,
     CSVImport.findMessageTypeIdByName(
     (String)inputMap.get("Message Type"),
     (String)inputMap.get("Category")));
list.add(messageMap);

return list;