Name
global.AssetFixScriptUtil
Description
Script include that contains a class to help relabel fields to specified label
Script
var AssetFixScriptUtil = Class.create();
AssetFixScriptUtil.renameFieldLabel = function(table, field, newLabel, newHint) {
// update field label
var docGr = new GlideRecord('sys_documentation');
docGr.addQuery('name', table);
docGr.addQuery('element', field);
docGr.addQuery('label', '!=', newLabel);
docGr.addQuery('language', 'en');
docGr.query();
if (docGr.next()) {
docGr.setValue('label', newLabel);
if (newHint) {
docGr.setValue('hint', newHint);
}
docGr.update();
}
// update dictionary entry
var dictGr = new GlideRecord('sys_dictionary');
dictGr.addQuery('name', table);
dictGr.addQuery('element', field);
dictGr.addQuery('column_label', '!=', newLabel);
dictGr.query();
if (dictGr.next()) {
dictGr.setValue('column_label', newLabel);
dictGr.update();
}
};
AssetFixScriptUtil.renameChoiceLabel = function(table, element, choiceLabel, choiceValue) {
var gr = new GlideRecord('sys_choice');
gr.addQuery('name', table);
gr.addQuery('value', choiceValue);
gr.addQuery('element', element);
gr.query();
if (gr.next()) {
gr.setValue('label', choiceLabel);
gr.update();
}
};
AssetFixScriptUtil.setAttribute = function(table, field, newValue) {
var gr = new GlideRecord('sys_dictionary');
gr.addQuery('name', table);
gr.addQuery('element', field);
gr.query();
if (gr.next()) {
var result = '';
var currAttr = gr.getAttribute();
if (!gs.nil(currAttr)) {
result = currAttr + ',';
}
result += newValue;
gr.setValue('attributes', result);
gr.update();
}
};
AssetFixScriptUtil.updateDictionaryAttribute = function(table, field, columnName, columnValue) {
var gr = new GlideRecord('sys_dictionary');
gr.addQuery('name', table);
gr.addQuery('element', field);
gr.query();
if (gr.next()) {
gr.setValue(columnName, columnValue);
gr.update();
}
};
AssetFixScriptUtil.updateTableAttribute = function(table, columnName, columnValue) {
var gr = new GlideRecord('sys_db_object');
gr.addQuery('name', table);
gr.query();
if (gr.next()) {
gr.setValue(columnName, columnValue);
gr.update();
}
};
Sys ID
e752913c0df8a110f877b8a611a9670f