Scripts for Exporting


Hint

Prefer the header-based over the index-based approach for more flexibility!


Header-based Export Script

Goals

  • Format EFFECTIVE_DATE
  • Export values that are referenced from another data object (see MANAGER and CURRENCY_CODE)
  • Map boolean values to text (strings)

Initial Situation

The fields in Feeder were spelled as the target SuccessFactors expects it.This simplifies the export and saves mapping efforts.

Feeder Export Headline (1) - Common BizX Fields:

  • USERID,USERNAME,STATUS,FIRSTNAME,MI,LASTNAME,GENDER,EMAIL,EMPID,HIREDATE,
  • MANAGER,MATRIX_MANAGER,HR,DEPARTMENT,JOBCODE,DIVISION,LOCATION,
  • BIZ_PHONE,FAX,ADDR1,ADDR2,CITY,STATE,ZIP,COUNTRY,
  • TIMEZONE,DEFAULT_LOCALE,CUSTOM01,CUSTOM02,CUSTOM03 (etc.)

Additional Fields:

  • IS_MANAGER,HOME_OFFICE,BASE_SALARY,DATE_OF_BIRTH,EFFECTIVE_DATE,CURRENCY_CODE

Header-based Export Script

Please note that fall-through-case- notation is used, which reduces coding extent.

var i, name, col;
var efDate = Helper.getEffectedDate('dd.MM.yyyy');

for (i = 0; i < headers.length; i++) {

    name = toStr(headers[i]);
    col = obj.get(name);

    switch (name) {
            // Map boolean values to text (strings)
        case 'IS_MANAGER':
        case 'HOME_OFFICE':
            columns[i] = (toStr(col)) === 'true' ? 'y' : 'n';
            break;
        case 'BASE_SALARY':
            columns[i] = Helper.formatNumber(col, '0.##/D./G,');
            break;
        case 'DATE_OF_BIRTH':
            columns[i] = Helper.formatDate(col, 'dd.MM.yyyy');
            break;
        case 'EFFECTIVE_DATE':
            columns[i] = efDate;
            break;

        // Export values of a (self-referenced) data object
        case 'MANAGER':
            if(col){
                columns[i] = col.get('FIRSTNAME') +" "+ col.get('LASTNAME');
            }
            break;

        // Export values of an (external) data object
        case 'CURRENCY_CODE':
            if(col){
            columns[i] = col.get('CURRENCY_CODE');
            }
            break;
    default:
        columns[i] = col;
    }
}

Code Comments

  • Formatting data ca be done via the corresponding Helper functions, e.g. getEffectedDate(…)
  • Maping boolean values to text (strings): On the left hand side of the equal sign, the boolean values of true and false are first transformed to strings. In a second step, a comparison takes place and the strings ‘y’ or ‘n’will be set (‘true’===’true’ -> ‘y’;’false’===’true’ ->’n’)
  • Reference attributes need to be scripted. Otherwise the exported value would be a non-readable GenericObject(id=null, properties={CURRENCY_NAME=Euro, CURRENCY_CODE=EUR}, type=null) Please consider further reading on the Currency Object Implementation

Currency Object Implementation

In the System Configuration

image0

In the User Management

image2

The reference attribute in the SF_User object (System Configuration)

image1


Index-based Export Script

Goals

  • Realize index-based mapping
  • Use short notation in coding
  • Map to different headers

Initial Situation & Indexing

Feeder’s export headline:

  • LASTNAME,FIRSTNAME,GENDER,NATIONALITY, DOB ,POSITION

Target system’s required headline:

  • LASTNAME,FIRSTNAME,GENDER,NATIONALITY, DateOfBirth(dd/MM/yyyy) ,POSITION

Indexing:

columns[0] columns[1] columns[2] columns[3] columns[4] columns[5]
LASTNAME FIRSTNAME GENDER NATIONALITY DOB POSITION

Index-based Export Script

Supposing that Feeder uses the technical names “DOB” for date of birth and the target system requires a header name “DateOfBirth(dd/MM/yyyy)”, then this can be realized with the following script where deviating Feeder headers are translated to the target-specific header names .

Note

Please keep in mind that this code transforms further headers, e.g. STARTDATE -> StartDate etc.

// this loop iterates over the Feeder mapping headline and is executed for every (user) record
for (var i = 0; i < headers.length; i++) {

    // headline alias header sequence of the Feeder export setting
    var key = headers[i];

    // map deviating header names to the names required by the target system
    if (i == 5)
        key = "DateOfBirth(dd/MM/yyyy)";
    if (i == 15)
        key = "StartDate";
    if (i == 19)
        key = "InPositionSince";
    if (i == 20)
        key = "DateJoined";

    // take the record (obj), get the value at the particular index position and transform
    var s = obj.get(key);
    if (i == 5) {
        s = Helper.formatDate(s, "dd/MM/yyyy");
    }
    if (i == 15) {
        s = Helper.formatDate(s, "dd/MM/yyyy");
    }
    if (i == 19) {
        s = Helper.formatDate(s, "dd/MM/yyyy");
    }
    if (i == 20) {
        s = Helper.formatDate(s, "dd/MM/yyyy");
    }
    if (s == null)
        s = "";

    // print the values of the user record
    columns[i] = s;
}

Short notation of the index-based sample export script:

for (var i = 0;i < headers.length;i++){

    var key = headers[i];
    if (i == 5) key = "DateOfBirth(dd/MM/yyyy)";
    if (i == 15) key = "StartDate";
    if (i == 19) key = "InPositionSince";
    if (i == 20) key = "DateJoined";

    var s = obj.get(key);
    if (i == 5 || i == 15 || i == 19 || i == 20) {
        s = Helper.formatDate(s,"dd/MM/yyyy");
    }

    if (s == null) s = "";

    columns[i] = s;
}

Code Comments

  • The sequence of attributes in the export setting has to be known to address the correct column!
  • if (i == 5) key = “DOB”; equals notation with curly braces if (i == 5){ key = “DOB”};

Exporting Multivalue Fields

As of Feeder v2.0, you can export a multi value field which is actually an attribute flagged in the Multivalue option within the Attribute Configuration.

case 'MultiValTest':
    var result = [];
    for (var j = 0; j < value.length; j++) {
        result.push(toStr(value[j]));
    }
    columns[i] = result.join();
    break;

Hint

When using Scripting to export mulit value fields, please remember that the values need to be transformed into strings beforehand!


Last Effective Change

The Feeder differentiates between a technical change of a field that will not be tracked and a so-called Effective Change that will create an actual entry in the change history.

Example

A Customer Object possesses a field Import Source. The value of this field consists of <Source>_<DateTime> and will be updated every single day. In addition, a Delta Export will also be executed in parallel.

  • Last Modified as tracking criteria:
    If the Delta Import considers Last Modified as a tracking criteria, all customer objects would be exported.
  • Last Effective Change as tracking criteria:
    If the Delta Import considers Last Effective Change as a criteria, none of the customer objects would not be considered to be exported.
var lec = obj.get('_LastEffectiveChange');
if (lec== null) {
        return false;
}
modified = toDate(lec);