Name
global.HRMigrationUtil
Description
Utility class for HR Migration
Script
var HRMigrationUtil = Class.create();
HRMigrationUtil.prototype = {
initialize: function() {
this.ALLOWED_GLOBAL_TABLES = ['sys_dictionary', 'sys_group_has_role', 'sys_user_has_role', 'sys_choice'];
},
/*
* updateRecord - global method available to dictionary entries of HR Scoped application tables
* Only the dictionary entries belonging to HR Scoped application tables are allowed to update
* @param
* tableName - String - global table in which record is being inserted
* encQuery - String - encoded query string with fields and values to query from the table
* setFields - JS Object - JS Object with fields and values to set the fields
*
* returns boolean
* true - if error
* false - if no error and update is successful
*/
updateRecord: function(tableName, encQuery, setFields){
var error = false;
//Verify the table is 'sys_dictionary' AND only dictionary entries belonging to HR Scoped tables are updated
if(tableName == 'sys_dictionary' && encQuery.indexOf('name=sn_hr') > -1) {
try{
var result = '';
var grTable = new GlideRecord(tableName);
grTable.addEncodedQuery(encQuery);
grTable.setLimit(1);
grTable.query();
if(grTable.next()) {
for(var setField in setFields)
if (setFields.hasOwnProperty(setField))
grTable.setValue(setField, setFields[setField]);
result = grTable.update();
}
if(gs.nil(result))
error = true;
}
catch(err){
error = true;
}
}
return error;
},
/*
* updateGlobalRecord - global method available to update records into global tables from HR
* Scoped application.
* the global tables allowed are - sys_dictionary, sys_choice
* @param
* tableName - String - global table in which record is being inserted
* encQuery - String - encoded query string with fields and values to query from the table
* setFields - JS Object - JS Object with fields and values to set the fields
*
* returns boolean
* true - if error
* false - if no error and update is successful
*/
updateGlobalRecord: function(tableName, encQuery, setFields){
var error = false;
if((tableName == 'sys_choice' || tableName == 'sys_dictionary') && encQuery.indexOf('name=sn_hr') > -1) {
try{
var result = '';
var grTable = new GlideRecord(tableName);
grTable.addEncodedQuery(encQuery);
grTable.query();
while(grTable.next()) {
for(var setField in setFields)
if (setFields.hasOwnProperty(setField))
grTable.setValue(setField, setFields[setField]);
result = grTable.update();
}
if(gs.nil(result))
error = true;
}
catch(err){
error = true;
}
}
return error;
},
/*
* insertRecord - global method available to insert records into global tables from HR Scoped application
* the global tables allowed are - sys_dictionary, sys_group_has_role, sys_user_has_role
* @param
* tableName - String - global table in which record is being inserted
* fields - JS Object - JS Object with fields and values for the fields
*
* returns boolean
* true - on successful insertion
* false - on unsuccessful insertion
*/
insertRecord : function(tableName, fields){
var error = false;
if(this.ALLOWED_GLOBAL_TABLES.indexOf(tableName) > -1) {
try{
var result = '';
var grTable = new GlideRecord(tableName);
//Loop through fields and set its values
for (var field in fields)
if (fields.hasOwnProperty(field))
grTable.setValue(field, fields[field]);
result = grTable.insert();
if(gs.nil(result))
error = true;
}
catch(err){
error = true;
}
}
return error;
},
type: 'HRMigrationUtil'
};
Sys ID
dfa6a2319f7222003be01050a57fcf39