.. index:: !Exports .. _Frontend Scripts Exports: Scripts for Exporting ============================================= - :ref:`Advanced Export` - :ref:`Currency Object Implementation` - :ref:`Basic Export Indexed` - :ref:`Multiline Fields` - :ref:`Last Effective Change` --------------------------------------------- .. hint:: Prefer the **header-based** over the *index-based approach* for more flexibility! --------------------------------------------- .. _Advanced Export: Header-based Export Script ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. rubric:: Goals - Format EFFECTIVE\_DATE - Export values that are referenced from another data object (see MANAGER and CURRENCY_CODE) - Map boolean values to text (strings) .. rubric:: 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 .. rubric:: Header-based Export Script Please note that :ref:`fall-through-case- notation ` is used, which reduces coding extent. .. code:: javascript 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; } } .. rubric:: Code Comments - Formatting data ca be done via the corresponding :ref:`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') - :ref:`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 :ref:`Currency Object Implementation` --------------------------------------------- .. _Currency Object Implementation: Currency Object Implementation ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. rubric:: In the System Configuration |image0| .. rubric:: In the User Management |image2| .. rubric:: The reference attribute in the SF\_User object (System Configuration) |image1| --------------------------------------------- .. _Basic Export Indexed: Index-based Export Script ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. rubric:: Goals - Realize index-based mapping - Use short notation in coding - Map to different headers .. rubric:: 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 | +--------------+--------------+--------------+--------------+--------------+--------------+ .. rubric:: 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. .. code:: javascript // 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; } .. rubric:: Short notation of the index-based sample export script: .. code:: javascript 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; } .. rubric:: 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"};* --------------------------------------------- .. _Multiline Fields: 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 :ref:`Attribute Configuration `. .. code:: javascript 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: 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. .. rubric:: Example A **Customer Object** possesses a field ``Import Source``. The value of this field consists of ``_`` 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. .. code:: javascript var lec = obj.get('_LastEffectiveChange'); if (lec== null) { return false; } modified = toDate(lec); .. |image0| image:: /img/scripting/exports/expf_hager_currency_obj_conf.png .. |image1| image:: /img/scripting/exports/expf_hager_currency_obj_sfuser.png .. |image2| image:: /img/scripting/exports/currency_user_mgmt.png