Elements¶
This page explains the structure of import scripting on a high level basis:
The focus will be on the meaning of the Feeder-specific elements in a Sample Import Scenario:
For calculated fields:
For time slice migration scripts:
Sample Import Code¶
The following script will import data and extend the employees IDs by adding a preceding country code. The mapping methodology is further explained under How to Map.
var i, name, value;
for (i = 0; i < headers.length; i++) {
name = toStr(headers[i]);
value = toStr(columns[i]);
switch (name) {
case 'System_ID':
if (value != "") {
obj.set('Import_ID', 'OLV_' + value);
}
break;
case 'FirstName':
case 'LastName':
obj.set(name.toUpperCase(), value);
break;
case 'Email':
obj.set(name.toUpperCase(), value.toLowerCase());
break;
case 'Startdate':
var date = Helper.parseDate(value, 'dd.MM.yyyy');
if (date != null) {
obj.set('HIREDATE', date);
}
break;
default:
obj.set(name, value);
break;
}
}
obj.set('TEST_DATA', true);
Important
The script will be run for every single row of data in the csv data file!
Code Structure¶
This for-loop iterates over all column headers:
for (var i = 0; i < headers.length; i++) {
...
}
The column headers array is converted to an explicit JavaScript string and will be stored in a variable called name. The same is done for the columns array:
for (i = 0; i < headers.length; i++) {
name = toStr(headers[i]);
value = toStr(columns[i]);
...
}
In the switch-case-notation, the header names of the csv file that are stored in the headers array, are mapped to the Feeder field names:
var i, name, value;
for (i = 0; i < headers.length; i++) {
name = toStr(headers[i]);
value = toStr(columns[i]);
switch (name) {
case 'System_ID':
if (value != "") {
obj.set('Import_ID', 'OLV_' + value);
}
break;
case 'FirstName':
case 'LastName':
obj.set(name.toUpperCase(), value);
break;
case 'Email':
obj.set(name.toUpperCase(), value.toLowerCase());
break;
case 'Startdate':
var date = Helper.parseDate(value, 'dd.MM.yyyy');
if (date != null) {
obj.set('HIREDATE', date);
}
break;
...
}
}
- A prefix is added to the System_ID value that is imported and stored in Import_ID
- The column header value of e.g. FirstName is mapped to the field FIRSTNAME
- The cell values in Email are transformed to lower case and stored in EMAIL
- The Startdate value is converted to an explicit JavaScript date. The date format specifies what format is to be expected/ delivered by the import file
Hint
Multiple case arguments listed after one another reduce the writing effort and will run the same code for both ‘FirstName’and ‘LastName’
The default case will import the values of all columns where the spelling of the csv column header name is the same as the field name in Feeder:
var i, name, value;
for (i = 0; i < headers.length; i++) {
name = toStr(headers[i]);
value = toStr(columns[i]);
switch (name) {
case 'System_ID':
...
break;
default:
obj.set(name, value);
break;
}
}
obj.set('TEST_DATA', true);
Hint
Outside of the for-loop, additional fields can be set in the import e.g. the boolean field TEST_DATA. This can be very useful allowing filtering on the field for identifying new imports.
Sample Import Scenario¶
The sample import file contains the following columns and record:
LastName | FirstName | System_ID | Startdate | |
Cione | Marina | MC@MAIL.com | MC100 | 05/01/2014 |
Assuming the following attributes in the FEEDER, the imported data set will be as follows:
LASTNAME | FIRSTNAME | Import_ID | HIREDATE | |
Cione | Marina | mc@mail.com | OLV_MC100 | 01.05.2014 |
headers¶
The headers-element is a central part of import scripting .
It embraces a list (array) of all column header names.
Typically, it is used in combination with the columns element and used in a loop or if-condition.
In the example above, it contains:
headers[] = {LastName,FirstName,Email,System_ID,Startdate}.
columns¶
The columns-element is a central part of import scripting .
Typically, it is used in combination with the headers element and used in a loop or if-condition.
It is a Java array alias list that contains all cell values of the import line (of the csv). The values are Java strings .
Thus it is required to convert them to real JavaScript using the toStr(‘..’) Feeder function.
In the example above, it contains:
columns[] = {Cione,Marina,MC@MAIL.com,MC100,05/01/2014}
obj & obj.set()¶
The obj-element embraces a Generic Object and will later be the actual data record in the Feeder.
The current import line will be mapped to the target values and thus to the record.
Taking the example above, it will then fully consist of:
obj = {Cione,Marina,mc@mail.com,OLV_MC100,01.05.2014}
In order to fill it with the particular values, it features one proprietary function in the import:
obj.set('feederAttributeName', newValue);
Feeder System Fields¶
Feeder will maintain the following system fields per record per default:
created¶
- Signals when a record was initially created
You may extract the values using the following functions:
// Both functions do the very same:
obj.getCreated();
obj.get('created');
feeder_state¶
- Gives feedback on the current state of a data record.
It may have 4 different states:
{}
when there is still information missing and a data record is incomplete129
when all mandatory fields have been filled and the record is complete32
when the data record is an incomplete potential duplicate After the validation step, the state will change to {}33
when the data record is a complete potential duplicate. After the validation step, the state will change to 129
You may extract the values using the following functions:
obj.get('feeder_state');
// Typical usage:
var m1 = toStr(obj.get('feeder_state')); // convert the value into a real String
if(m1 == '129'){
//...
}
Hint
Find a more detailed sample here: Attribute Visualization (Visualizing Code for the feeder_state)
modified & _lastModified¶
modified
signals when a record was last modified
obj.getModified();
obj.get('modified');
_lastModified
signals what was the second last time that a record was modified
obj.getLastModified();
obj.get('_lastModified');
Hint
Please be aware that the toStr(), toDate() et.al. functions might be needed to output or calculate further with the retrieved values.
currentTimeSlice¶
Important
This element is NOT meant for attribute, import or export scripting!
The currentTimeSlice-element contains data of the current time slice and can be used only in the process of future-based automatic time slice creation where it serves to manipulate certain values of a record. It features the following methods:
- getCreationDate()
- Returns the time slice ‘s creation date as Java(!) Date.
- getStartDate()
- Returns the time slice ‘s start date as Java(!) Date.
- getName()
- Returns the time slice ‘s name as string.
- isCreated()
- Returns either true or false as boolean.
Hint
Please be aware that this method returns a Java Date, which is why the Feeder’s toDate() method has to be applied to convert it to a JavaScript Date.