Import persons into custom actor

From SMTX Wiki
Jump to navigation Jump to search

The script below was written to import people from a CSV file as actor in a service, for which only the id was available. The actor field was a custom multi person field.

var file=#1#; //The CSV file comes here. Structure: header on top, per line: serviceid, servicename, actoremail
var fileLines=file.split('\r\n');
var log=[];
var allServices = JSON.parse(ServiceCatalogInterface.getAllServicesSummary());
for (var i=1; i< fileLines.length; i++) {
  var newActor=fileLines[i].split(';');
  if (newActor.length === 3 && newActor[2]) {
     var service = allServices.filter(function(s) { return s.id === +newActor[0]});
     if (service && service.length === 1 && service[0].template && service[0].template.name === 'Regelgeving - HBBZ') {
        CommonInterface.callWebservice('Services: add person to service person list', { 
           'ServiceGuid': service[0].guid, 
           'TypeName': 'CustomActor', 
           'CustomActorInternalName': 'Redactieteam',
           'ActorPerson': '1',
           'Person': newActor[2],
           'ProviderName': 'xxx',
           'SecurityCheck': 'xxxx',
        });
     log.push('Person ' + newActor[2] + ' added to service id ' + service[0].id + ' (' + service[0].guid + ') ' + service[0].name);
     }
  }
}
return log.join('\n');