Name
sn_irm_shared_cmn.IRMUIUtils
Description
Utility methods to provide data for UI pages.
Script
var IRMUIUtils = Class.create();
IRMUIUtils.prototype = (function() {
var TABLES = {
// Common workspace tables
TABLE_HIGHLIGHTED_VALUE_CONDITION: 'sys_highlighted_value_condition',
TABLE_HIGHLIGHTED_VALUE_M2M_UX_CONFIG: 'sys_ux_m2m_highlighted_value_config',
TABLE_RULE_VIEW_WORKSPACE: 'sysrule_view_workspace',
TABLE_RULE_VIEW_WORKSPACE_M2M_UX_VIEW_RULE: 'sys_ux_m2m_workspace_view_rule_ux_view_rule_config',
TABLE_SYS_HIGHLIGHTED_VALUE: 'sys_highlighted_value',
TABLE_SYS_UX_STYLE: 'sys_ux_style',
TABLE_UX_HEADER_CONFIG: 'sys_ux_header_config',
TABLE_UX_HIGHLIGHTED_VALUE_CONFIG: 'sys_ux_highlighted_value_config',
TABLE_UX_LIST: 'sys_ux_list',
TABLE_WORKSPACE_FORM_HEADER: 'sys_aw_form_header',
TABLE_WORKSPACE_M2M_UX_HEADER_CONFIG: 'sys_ux_m2m_workspace_header_ux_header_config',
TABLE_WORKSPACE_FORM_HEADER_SECONDARY_VALUES: 'sys_aw_form_header_secondary_values',
// Common platform tables
TABLE_SYS_UI_LIST: 'sys_ui_list',
TABLE_SYS_UI_LIST_ELEMENT: 'sys_ui_list_element',
};
var USER_PREFREENCE = {
POLARIS_THEME_VARIANT: 'glide.ui.polaris.theme.variant',
};
// cache configuration results in this class instance for better performance when retrieving the same data.
var configCache = {
highlightedValueConfig: {},
};
var glideUtils;
/** @type {IRMLogger} */
var logger;
/** @type {*} */
var self;
/**
* Get Display value for an element as Highlighted value.
* @private
* @param {GlideElement} element - Element (Field) to display as highlighted value.
* @param {highlightedValue} highlightedValue - Highlighted value properties.
* @returns {Object} displayValueProps.
*/
function getElementDisplayValueAsHighlightedValue(element, highlightedValue) {
var label = element.getLabel();
var value = element.getDisplayValue();
if (!value) {
return { label: label, value: null };
}
return self.generateDisplayValueAsHighlightedValue(label, {
highlightedValue: highlightedValue,
});
}
/**
* Get Display value for an element as Reference.
* @private
* @param {GlideElement} element - GlideElement to retrieve field information from.
* @returns {Object} displayValueProps - Object for Reference value.
*/
function getElementDisplayValueAsReference(element) {
var label = element.getLabel();
var value = element.toString();
if (!value) {
return { label: label, value: null };
}
var displayValue = element.getDisplayValue();
return self.generateDisplayValueAsReference(label, displayValue, value, {
data: {
fieldName: element.getName(),
fieldLabel: element.getLabel(),
displayValue: displayValue,
table: element.getReferenceTable(),
sysId: value,
},
});
}
/**
* Get Display value for an element as a String.
* @private
* @param {GlideElement} element - GlideElement to retrieve field information from.
* @returns {Object} displayValueProps - Object for string value.
*/
function getElementDisplayValueAsString(element) {
var label = element.getLabel();
var value = element.getDisplayValue();
if (!value) {
return { label: label, value: null };
}
return self.generateDisplayValueAsString(label, value, {
data: {
fieldName: element.getName(),
fieldLabel: label,
displayValue: element.getDisplayValue(),
},
});
}
/**
* Get UX form header config record by table name.
* @private
* @param {String} table - Table name.
* @returns {GlideRecord} record.
*/
function getFormHeaderConfigRecord(table) {
var headerConfigId = self.headerConfigId;
if (gs.nil(headerConfigId)) {
logger.warn('No header config ID provided. Unable to retrieve header configuration for table: ' + table);
return null;
}
var formHeaderConfig = new GlideRecord(TABLES.TABLE_WORKSPACE_M2M_UX_HEADER_CONFIG);
formHeaderConfig.addQuery('header_config', headerConfigId);
formHeaderConfig.addQuery('workspace_form_header.table', table);
formHeaderConfig.setLimit(1);
formHeaderConfig.query();
if (!formHeaderConfig.next()) {
logger.warn('Unable to find form header configuration for table ' + table + ' with header config ID ' + headerConfigId);
return null;
}
var formHeaderConfigRecord = formHeaderConfig.workspace_form_header && formHeaderConfig.workspace_form_header.getRefRecord();
if (!formHeaderConfigRecord.isValidRecord()) {
logger.warn('Sys ID "' + formHeaderConfig.getValue('workspace_form_header') + '" is not valid for form header configuration. (' + TABLES.TABLE_WORKSPACE_FORM_HEADER + ')');
return null;
}
return formHeaderConfigRecord;
}
/**
* Get highlighted value condition records.
* @private
* @param {String} highlightedValueId - SysID for highlighted value record.
* @returns {GlideRecord} records.
*/
function getHighlightedValueConditionRecordByConfigId(highlightedValueId) {
var highlightedValueConditionRecords = new GlideRecord(TABLES.TABLE_HIGHLIGHTED_VALUE_CONDITION);
highlightedValueConditionRecords.addQuery('highlighted_value', highlightedValueId);
highlightedValueConditionRecords.orderBy('order');
highlightedValueConditionRecords.query();
return highlightedValueConditionRecords;
}
/**
* Get highlighted value record.
* @private
* @param {String} table - Table name.
* @param {String} field - Field name.
* @returns {GlideRecord} record.
*/
function getHighlightedValueConfigRecord(table, field) {
var highlightedValueConfigId = self.highlightedValueConfigId;
if (gs.nil(highlightedValueConfigId)) {
logger.warn('No highlighted value config ID provided. Unable to retrieve highlighted value configuration for table: ' + table);
return null;
}
var highlightedValueConfig = new GlideRecord(TABLES.TABLE_HIGHLIGHTED_VALUE_M2M_UX_CONFIG);
highlightedValueConfig.addQuery('highlighted_value_config', highlightedValueConfigId);
highlightedValueConfig.addQuery('highlighted_value.table', table);
highlightedValueConfig.addQuery('highlighted_value.field', field);
highlightedValueConfig.orderBy('order');
highlightedValueConfig.setLimit(1);
highlightedValueConfig.query();
if (!highlightedValueConfig.next()) {
logger.debug('Unable to find form highlighted value configuration for table "' + table + '" / field "' + field + '" with highlighted config ID: ' + highlightedValueConfigId);
return null;
}
var highlightedValueConfigRecord = highlightedValueConfig.highlighted_value && highlightedValueConfig.highlighted_value.getRefRecord();
if (!highlightedValueConfigRecord.isValidRecord()) {
logger.warn('Sys ID "' + highlightedValueConfigRecord.getValue('highlighted_value') + '" is not valid for highlighted value configuration. (' + TABLES.TABLE_SYS_HIGHLIGHTED_VALUE + ')');
return null;
}
return highlightedValueConfigRecord;
}
/**
* Get secondary value field object for Display block value.
* @private
* @param {GlideRecord} record - Record to retrieve data from.
* @param {String} field - Field name.
* @param {Object} options - Options to configure this method output.
* @param {String[]} options.disableReference - List of table names where a reference link should be disabled.
* @returns {Object} fieldData - Object for Display block value.
*/
function getSecondaryValueFieldData(record, field, options) {
var _options = options || {};
var disableReference = _options.disableReference || [];
var element = record.getElement(field);
var descriptor = element.getED();
var fieldType = descriptor.getInternalType();
var displayValue;
var highlightedValue = self.getHighlightedValueForRecord(record, field);
if (highlightedValue) {
fieldType = 'highlighted';
}
switch (fieldType) {
case 'highlighted': {
displayValue = getElementDisplayValueAsHighlightedValue(element, highlightedValue);
break;
}
case 'reference': {
var refTable = element.getReferenceTable();
var isReferenceDisabled = Array.isArray(disableReference) && disableReference.indexOf(refTable) >= 0;
displayValue = isReferenceDisabled ?
getElementDisplayValueAsString(element) : getElementDisplayValueAsReference(element);
break;
}
case 'string': {
displayValue = getElementDisplayValueAsString(element);
break;
}
default: {
displayValue = getElementDisplayValueAsString(element);
}
}
return displayValue;
}
/**
* Get secondary value records by form header config ID
* @private
* @param {String} formHeaderConfigID - Form header config ID.
* @returns {GlideRecord} record.
*/
function getSecondaryValueRecordByFormHeader(formHeaderConfigID) {
var secondaryValueRecords = new GlideRecord(TABLES.TABLE_WORKSPACE_FORM_HEADER_SECONDARY_VALUES);
secondaryValueRecords.addActiveQuery();
secondaryValueRecords.addQuery('form_header', formHeaderConfigID);
secondaryValueRecords.orderBy('order');
secondaryValueRecords.query();
return secondaryValueRecords;
}
/**
* Get an instance of IRMGlideUtils utils.
* @returns {IRMGlideUtils} glideUtils
*/
function getGlideUtils() {
if (typeof glideUtils === 'undefined') {
glideUtils = new IRMGlideUtils({ logger: logger });
}
return glideUtils;
}
/**
* Insert additional display value items to secondary value configurations.
* @private
* @param {Object[]} secondaryValues - Current list of secondary values.
* @param {Object[]} additionalItems - Additional items to insert.
* @returns {Object[]} secondaryValues
*/
function insertAdditionalSecondaryValues(secondaryValues, additionalItems) {
additionalItems.forEach(function (newValue) {
var item = newValue.item;
var index = newValue.index;
secondaryValues.splice(index, 0, item);
});
return secondaryValues;
}
return {
initialize: function (options) {
/** @type {*} */
self = this;
var _options = options || {};
logger = _options.logger || {
info: gs.info,
debug: gs.debug,
warn: gs.warn,
error: gs.error,
};
self.headerConfigId = _options.headerConfigId;
self.highlightedValueConfigId = _options.highlightedValueConfigId;
self.viewRuleConfigId = _options.viewRuleConfigId;
},
/**
* Method to generate alert message object for workspace.
* @param {string} content - Message content for alert message.
* @param {AlertMessageOptions} [options] - Options to configure Alert message UI.
* @typedef {Object} AlertMessageOptions
* @property {Object} [action] - Actions object for Alert message. Defaults to dismiss action.
* @property {string} [icon='info-circle-outline'] - Alert message icon. Defaults to `info-circle-outline`.
* @property {string} [status='info'] - Alert message status. Defaults to `info`.
* @returns {Object} alert
*/
generateAlertMessage: function(content, options) {
var _options = options || {};
var action = _options.action || { type: 'dismiss' };
var icon = _options.icon || 'info-circle-outline';
var status = _options.status || 'info';
return {
id: gs.generateGUID(),
action: action,
content: content,
icon: icon,
status: status,
};
},
/**
* Method to generate Error alert message object for workspace.
* @param {string} content - Message content for alert message.
* @param {AlertMessageOptions} [options] - Options to configure Alert message UI.
* @returns {Object} alert
*/
generateAlertErrorMessage: function(content, options) {
var _options = options || {};
_options.icon = _options.icon || 'triangle-exclamation-outline';
_options.status = 'critical';
return this.generateAlertMessage(content, _options);
},
/**
* Method to generate Info alert message object for workspace.
* @param {string} content - Message content for alert message.
* @param {AlertMessageOptions} [options] - Options to configure Alert message UI.
* @returns {Object} alert
*/
generateAlertInfoMessage: function(content, options) {
var _options = options || {};
_options.icon = _options.icon || 'info-circle-outline';
_options.status = 'info';
return this.generateAlertMessage(content, _options);
},
/**
* Generate Highlighted value object for Display value component properties.
* @param {String} label - Display value label.
* @param {Object} options - Display value additional configurations.
* @param {Object} options.data - Additional data to attach into Display value data object.
* @param {highlightedValue} options.highlightedValue - Highlighted value properties.
* @returns {type} highlightedValueProps.
*/
generateDisplayValueAsHighlightedValue: function (label, options) {
var _options = options || {};
var additionalData = _options.data || {};
var highlightedValue = _options.highlightedValue || {};
var color = highlightedValue.color || '';
var icon = highlightedValue.icon || '';
var showIcon = highlightedValue.showIcon || false;
var status = highlightedValue.status || '';
var variant = highlightedValue.variant || '';
var value = highlightedValue.label;
var data = IRMCoreUtils.objectAssign({
status: status,
showIcon: showIcon,
variantName: variant,
colorName: color,
iconName: icon,
type: 'highlighted',
}, additionalData);
var displayValue = {
label: label,
value: {
type: 'highlighted-value',
label: value,
showIcon: showIcon,
status: color,
data: data,
},
};
if (showIcon) {
displayValue.value.icon = icon;
}
return displayValue;
},
/**
* Generate Reference link object for Display value component properties.
* @param {String} label - Display value label.
* @param {String} displayValue - Reference display value.
* @param {String} value - Reference value.
* @param {Object} options - Display value additional configurations.
* @param {Object} options.data - Additional data to attach into Display value data object.
* @returns {type} referenceValueProps
*/
generateDisplayValueAsReference: function (label, displayValue, value, options) {
var _options = options || {};
var additionalData = _options.data || {};
var data = IRMCoreUtils.objectAssign({ type: 'reference' }, additionalData);
return {
label: label,
value: {
value: value,
type: 'text-link',
label: displayValue,
href: 'javascript:void(0)',
data: data,
},
};
},
/**
* Generate String object for Display value component properties.
* @param {String} label - Display value label.
* @param {String} displayValue - Display value string.
* @param {Object} options - Display value additional configurations.
* @param {Object} options.data - Additional data to attach into Display value data object.
* @returns {Object} referenceValueProps
*/
generateDisplayValueAsString: function (label, value, options) {
var _options = options || {};
var additionalData = _options.data || {};
var data = IRMCoreUtils.objectAssign({ type: 'simple' }, additionalData);
return {
label: label,
value: {
value: value,
type: 'string',
data: data,
},
};
},
/**
* Generate object for Highlighted value component properties.
* @param {String} _label - Highlighted value label.
* @param {String} color - Highlighted value color.
* @param {String} variant - Highlighted value variant.
* @param {Object} options - Highlighted value additional configurations.
* @param {Boolean} options.showIcon - Whether or not the Highlighted value should show icon.
* If no icon is specified it will show a dot.
* @param {String} options.icon - Highlighted value icon.
* @param {String} options.status - Highlighted value status.
* @param {String} options.valueOverride - Highlighted value override value (will replace original label).
* @returns {Object} highlightedValueProps.
*/
generateHighlightedValue: function (label, color, variant, options) {
var _options = options || {};
var icon = _options.icon || '';
var showIcon = _options.showIcon || false;
var status = _options.status || '';
var highlightedValue = {
color: color,
label: label,
showIcon: showIcon,
status: status,
variant: variant,
};
if (showIcon && icon) {
highlightedValue.icon = icon;
}
return highlightedValue;
},
/**
* Get header values for a record.
* @param {String} table - table name.
* @param {String} sysId - SysID for the record.
* @returns {Object} formHeaderValues
*/
getFormHeaderValues: function(table, sysId) {
/** @type {*} */
self = this;
var results = null;
try {
var record = getGlideUtils().getGlideRecordById(table, sysId);
if (!record) {
return results;
}
var formHeaderConfigRecord = getFormHeaderConfigRecord(table);
if (!formHeaderConfigRecord) {
return results;
}
results = {};
var primaryField = formHeaderConfigRecord.getValue('primary_field');
var primaryFieldValue = record.getElement(primaryField);
var subheadingField = formHeaderConfigRecord.getValue('subheading');
var subheadingValue = record.getElement(subheadingField);
if (primaryFieldValue) {
results.primaryField = primaryFieldValue.getDisplayValue();
}
if (subheadingValue) {
results.subheading = subheadingValue.getDisplayValue();
}
return results;
} catch (error) {
// eslint-disable-next-line sonarjs/no-duplicate-string
logger.error('Error retrieving "Form header values" for record "' + sysId + '" in table "' + table + '".\n' + error);
return results;
}
},
/**
* Get highlighted value for a record by SysID.
* @param {String} table - table name.
* @param {String} sysId - SysID for the record.
* @param {String} field - Field to retrieve highlighted value for.
* @returns {Object} highlightedValue - highlighted value for the record
*/
getHighlightedValue: function(table, sysId, field) {
/** @type {*} */
self = this;
var results = null;
try {
var record = getGlideUtils().getGlideRecordById(table, sysId);
if (!record) {
return results;
}
return self.getHighlightedValueForRecord(record, field);
} catch (error) {
logger.error('Error retrieving ' + field + '"Highlighted value" for table "' + table + '" (' + sysId + ')"\n' + error);
return results;
}
},
/**
* Get highlighted value for a record.
* @param {GlideRecord} record - GlideRecord to get highlighted value for.
* @param {String} field - Field to retrieve highlighted value for.
* @returns {Object} highlightedValue - highlighted value for the record
*/
getHighlightedValueForRecord: function (record, field, options) {
/** @type {*} */
self = this;
var _options = options || {};
var skipCache = _options.skipCache || false;
var found = false;
try {
if (!record.isValidRecord()) {
logger.warn('Error: Invalid record. No highlighted value available.');
return null;
}
var cacheKey = [record.getTableName(), record.getUniqueValue(), field].join('/');
if (!skipCache && typeof configCache.highlightedValueConfig[cacheKey] !== 'undefined') {
return configCache.highlightedValueConfig[cacheKey];
}
var highlightedValueConfigRecord = getHighlightedValueConfigRecord(record.getTableName(), field);
if (!highlightedValueConfigRecord) {
configCache.highlightedValueConfig[cacheKey] = null;
return configCache.highlightedValueConfig[cacheKey];
}
var highlightedValueConditionRecords = getHighlightedValueConditionRecordByConfigId(highlightedValueConfigRecord.getUniqueValue());
while (highlightedValueConditionRecords.next() && !found) {
var condition = highlightedValueConditionRecords.getValue('conditions');
if (getGlideUtils().doesRecordMatchCondition(record, condition)) {
found = true;
break;
}
}
if (!found) {
configCache.highlightedValueConfig[cacheKey] = null;
return configCache.highlightedValueConfig[cacheKey];
}
var color = highlightedValueConditionRecords.getValue('color');
var icon = highlightedValueConditionRecords.getValue('icon');
var showIcon = highlightedValueConditionRecords.getValue('show_icon');
var status = highlightedValueConditionRecords.getValue('status');
var valueOverride = highlightedValueConditionRecords.getDisplayValue('value_override');
var variant = highlightedValueConditionRecords.getValue('variant');
var label = valueOverride || record.getDisplayValue(field);
configCache.highlightedValueConfig[cacheKey] = self.generateHighlightedValue(label, color, variant, {
icon: icon,
showIcon: showIcon === '1' || showIcon === 'true',
status: status,
});
return configCache.highlightedValueConfig[cacheKey];
} catch (error) {
logger.error('Error retrieving ' + field + '"Highlighted value" for record "' + record.getUniqueValue() + '" in table "' + record.getTableName + '".\n' + error);
return null;
}
},
/**
* Get list columns from a view.
* @param {String} table - Table name of the table whose columns from view we want.
* @param {String} view - View name (Will take default view if view is null or empty).
* @param {Object} options - Options to configure this method output.
* @param {String} options.parent - Table name of the parent table, if above table is a related list.
* @returns {String[]} columns - Array of column names.
*/
getListColumnsFromView: function(table, view, options) {
/** @type {*} */
self = this;
var _options = options || {};
var parent = _options.parent || '';
var columnsArr = [];
var DEFAULT_COLUMNS = ['sys_created_by', 'sys_created_on'];
if (gs.nil(table)) {
logger.error('Required parameters "table" cannot be null or empty.');
return null;
}
if (gs.nil(view)) {
view = '';
}
try {
var uiListGr = new GlideRecord(TABLES.TABLE_SYS_UI_LIST);
uiListGr.addQuery('name', table);
uiListGr.addQuery('view.name', view);
if (!gs.nil(parent)) {
uiListGr.addQuery('parent', parent);
}
uiListGr.orderByDesc('sys_updated_on');
uiListGr.setLimit(1);
uiListGr.query();
if (uiListGr.next()) {
var listId = uiListGr.getUniqueValue();
var uiListElementGr = new GlideRecord(TABLES.TABLE_SYS_UI_LIST_ELEMENT);
uiListElementGr.addQuery('list_id', listId);
uiListElementGr.orderBy('position');
uiListElementGr.query();
while (uiListElementGr.next()) {
columnsArr.push(uiListElementGr.getValue('element'));
}
} else {
logger.info('No record found in for "' + TABLES.TABLE_SYS_UI_LIST + '" for table "' + table + '" and view "' + view + '".');
return DEFAULT_COLUMNS;
}
} catch (error) {
logger.error('Error retrieving "Columns" for table "' + table + '" and view "' + view + '".\n' + error);
return null;
}
if (columnsArr.length > 0) {
return columnsArr;
}
return DEFAULT_COLUMNS;
},
/**
* Get the common Navigation event in UIB.
* @param {String} route - route name.
* @param {Object} options - options to pass a long with navigation evenTABLES.
* @param {Object} options.fields - URL fields to pass on the navigation payload.
* @param {Object} options.params - URL optional params to pass on the navigation payload.
* @returns {Object} event
*/
getNavigationEvent: function(route, _payload) {
var payload = IRMCoreUtils.objectAssign({
route: route,
fields: {},
params: {},
}, _payload);
return {
name: 'NAV_ITEM_SELECTED',
payload: payload,
};
},
/**
* Get header's secondary values for a record.
* @param {String} table - Table name.
* @param {String} sysId - SysID for the record.
* @param {Object} options - Options to configure this method output.
* @param {String[]} options.disableReference - List of table names where a reference link should be disabled.
* @returns {Object} secondaryValues - Secondary values in Display value block format.
*/
getSecondaryValues: function (table, sysId, options) {
/** @type {*} */
self = this;
var _options = options || {};
var additionalItems = _options.insert || [];
var results = [];
try {
var record = getGlideUtils().getGlideRecordById(table, sysId);
if (!record) {
insertAdditionalSecondaryValues(results, additionalItems);
return results;
}
return self.getSecondaryValuesForRecord(record, options);
} catch (error) {
logger.error('Error retrieving "Secondary values" for record "' + sysId + '" in table "' + table + '".\n' + error);
insertAdditionalSecondaryValues(results, additionalItems);
return results;
}
},
/**
* Get header's secondary values for a Glide record.
* @param {GlideRecord} record - GlideRecord instance to get Secondary values for.
* @param {Object} options - Options to configure this method output.
* @param {String[]} options.disableReference - List of table names where a reference link should be disabled.
* @returns {Object} secondaryValues - Secondary values in Display value block format.
*/
getSecondaryValuesForRecord: function (record, options) {
/** @type {*} */
self = this;
var _options = options || {};
var disableReference = _options.disableReference || [];
var additionalItems = _options.insert || [];
var results = [];
var sysId = record.getUniqueValue();
var table = record.getTableName();
try {
var formHeaderConfigRecord = getFormHeaderConfigRecord(table);
if (!formHeaderConfigRecord) {
insertAdditionalSecondaryValues(results, additionalItems);
return results;
}
var formHeaderConfigID = formHeaderConfigRecord.getUniqueValue();
var secondaryValueRecords = getSecondaryValueRecordByFormHeader(formHeaderConfigID);
while (secondaryValueRecords.next()) {
var conditions = secondaryValueRecords.getValue('conditions');
if (!getGlideUtils().doesRecordMatchCondition(record, conditions)) {
continue;
}
var roles = secondaryValueRecords.getValue('roles');
if (roles && !getGlideUtils().doesUserHaveRole(roles.split(','))) {
continue;
}
var field = secondaryValueRecords.getValue('field');
var fieldData = getSecondaryValueFieldData(record, field, {
disableReference: disableReference,
});
if (!fieldData.value) {
continue;
}
results.push(fieldData);
}
if (!results.length) {
logger.info('No secondary values found for table: ' + table);
}
insertAdditionalSecondaryValues(results, additionalItems);
return results;
} catch (error) {
logger.error('Error retrieving "Secondary values" for record "' + sysId + '" in table "' + table + '".\n' + error);
insertAdditionalSecondaryValues(results, additionalItems);
return results;
}
},
/**
* Get theme data for the current user.
* @typedef {Object} IRMThemeData
* @property {boolean} isDark - Indicate if the user has dark-mode on.
* @returns {IRMThemeData} output
*/
getThemeData: function() {
var output = {
isDark: false,
};
try {
var userTheme = gs.getUser().getPreference(USER_PREFREENCE.POLARIS_THEME_VARIANT);
var themeRecord = getGlideUtils().getGlideRecordById(TABLES.TABLE_SYS_UX_STYLE, userTheme, { secure: false });
if (!themeRecord) {
return output;
}
var style = JSON.parse(themeRecord.getValue('style'));
output.isDark = style.isDark === 'true';
return output;
} catch (err) {
logger.warn('Error retriving theme data for the user. ' + err.message);
return output;
}
},
/**
* Get list component configuration from UX List record.
* @param {string} listId - SysID for UX list to retrieve configuration for.
* @returns {Object} listConfig
*/
getUXListConfigurationById: function(listId) {
/** @type {*} */
self = this;
var CONFIG_FIELDS = [
'columns', 'condition', 'group_by_column', 'hide_cell_filter', 'hide_checkbox_hover',
'hide_column_filtering', 'hide_column_grouping', 'hide_column_resizing', 'hide_column_sorting', 'hide_drag_and_drop',
'hide_empty_state_image', 'hide_first_page', 'hide_header', 'hide_highlighted_values', 'hide_highlight_content',
'hide_inline_editing', 'hide_last_page', 'hide_last_refreshed_text', 'hide_links', 'hide_list_actions',
'hide_menu_button', 'hide_next_page', 'hide_option_to_save_as', 'hide_pages', 'hide_pagination',
'hide_panel_advanced', 'hide_panel_button', 'hide_panel_condition_delete', 'hide_panel_footer', 'hide_panel_restore',
'hide_personalization', 'hide_previous_page', 'hide_quick_edit', 'hide_range', 'hide_record_count_badge',
'hide_reference_links', 'hide_refresh_button', 'hide_rows_per_page_selector', 'hide_row_count', 'hide_row_selector',
'hide_select_all', 'hide_sharing_button', 'hide_title', 'highlight_content_color', 'highlight_content_pattern',
'max_characters', 'override_word_wrap_user_pref', 'table', 'title', 'view',
'word_wrap',
];
// List of fields to retrieve display values.
var displayValueFields = {
title: 1,
};
var listConfig = {};
var uxListRecord = getGlideUtils().getGlideRecordById(TABLES.TABLE_UX_LIST, listId, {
secure: false,
});
if (!uxListRecord) {
return listConfig;
}
CONFIG_FIELDS.forEach(function(field) {
var formattedField = IRMCoreUtils.snakeToCamel(field);
var value = displayValueFields[field] ? uxListRecord.getDisplayValue(field) : uxListRecord.getValue(field);
if (value === '0' || value === '1') {
listConfig[formattedField] = value === '1';
} else {
listConfig[formattedField] = value;
}
});
return listConfig;
},
/**
* Get UX lists, along their aggregated count data by category ID
* @param {string} categoryId - Category ID to retrieve UX Lists for.
* @returns {Object} results
*/
getUXListsByCategoryId: function(categoryId) {
/** @type {*} */
self = this;
var data = getGlideUtils().getGlideRecordData(TABLES.TABLE_UX_LIST, {
filter: 'category=' + categoryId,
orderBy: 'order',
secure: false,
select: ['condition', 'sys_id', 'table', { element: 'title', display: true }],
});
return data.map(function(record) {
var condition = record.condition;
var label = record.title;
var sysId = record.sys_id;
var table = record.table;
var count = getGlideUtils().getRecordCount(table, { filter: condition }) || 0;
var ariaProperties = {
button: { 'aria-label': gs.getMessage('{0} {1}', [label, count.toString()]) },
};
return {
count: count,
id: sysId,
label: label,
ariaProperties: ariaProperties,
};
});
},
/**
* Get view rule override.
* @param {GlideRecord} record - GlideRecord to get view configuration for.
* @returns {string} view SysID.
*/
getViewRuleOverride: function (record) {
/** @type {*} */
self = this;
var viewRuleConfigId = self.viewRuleConfigId;
var table = record.getTableName();
var view = '';
if (gs.nil(viewRuleConfigId)) {
logger.warn('No view rule config ID provided. Unable to retrieve view rule configurations for table: ' + table);
return view;
}
var viewRuleRecordMapping = new GlideRecord(TABLES.TABLE_RULE_VIEW_WORKSPACE_M2M_UX_VIEW_RULE);
viewRuleRecordMapping.addQuery('view_rules_configuration', viewRuleConfigId);
viewRuleRecordMapping.addQuery('workspace_view_rule.table', table);
viewRuleRecordMapping.orderBy('workspace_view_rule.order');
viewRuleRecordMapping.query();
while (viewRuleRecordMapping.next()) {
var viewRuleRecord = viewRuleRecordMapping.workspace_view_rule && viewRuleRecordMapping.workspace_view_rule.getRefRecord();
if (!viewRuleRecord.isValidRecord()) {
logger.warn('Sys ID "' + viewRuleRecordMapping.getValue('workspace_view_rule') + '" is not valid for view rule configuration. (' + TABLES.TABLE_RULE_VIEW_WORKSPACE + ')');
continue;
}
var condition = viewRuleRecord.getValue('condition');
if (getGlideUtils().doesRecordMatchCondition(record, condition)) {
view = viewRuleRecord.getValue('view');
break;
}
}
return view;
},
type: 'IRMUIUtils',
};
})();
Sys ID
a3558da6c3386110a6a1f51ca140dd8d