Name
sn_hr_integrations.HRIntegrationsDeptTransformHelper
Description
No description available
Script
var hrIntegrationsHelper = new HRIntegrationsHelper();
var HRIntegrationsDeptTransformHelper = Class.create();
HRIntegrationsDeptTransformHelper.prototype = {
initialize: function() {
// do nothing
},
transform: function(source, target) {
// Don't do any transformations for dry run.
if (hrIntegrationsHelper.isDryRun(source.source)) {
ignore = true;
hrIntegrationsHelper.logDebug("Dryrun is true hence creating departments is skipped " + source.name, hrIntegrations.HR_INT_LOADER_LOG);
return;
}
var departmentQuery;
var ccQuery;
if (action == "insert" && source.external_id) {
departmentQuery = new GlideRecord(hrIntegrations.DEPARTMENT_TABLE);
// action is 'insert', so let's create it and then set 'ignore = true'
departmentQuery.initialize();
// copy the target values to departmentQuery object manually.
for (var colKey in target) {
if (typeof colKey == 'string' && colKey.substring(0,"sys_".length) != "sys_") {
var colValue = target[colKey];
if (colValue)
departmentQuery.setValue(colKey,target[colKey]);
}
}
// Set the cost_center
if (source.cost_center) {
ccQuery = new GlideRecord("cmn_cost_center");
ccQuery.addQuery("code", source.cost_center);
ccQuery.query();
if (ccQuery.next())
departmentQuery.setValue("cost_center", ccQuery.sys_id);
}
departmentQuery.update();
// ask the transform to skip as we manually handled the insert case
ignore = true;
} else if (action == "update") {
// Set the cost_center
if (source.cost_center) {
ccQuery = new GlideRecord("cmn_cost_center");
ccQuery.addQuery("code", source.cost_center);
ccQuery.query();
if (ccQuery.next())
target.cost_center = ccQuery.sys_id;
}
}
},
type: 'HRIntegrationsDeptTransformHelper'
};
Sys ID
a6b2a5079fe032003be01050a57fcf9b