Name
sn_uibtk_api.UXAddOnEventMapping
Description
No description available
Script
const UXAddOnEventMapping = Class.create();
UXAddOnEventMapping.prototype = Object.extendsObject(BuilderToolkitAPIBase, {
TABLE: 'sys_ux_addon_event_mapping',
FIELDS: ['name', 'description', 'source_element_id', 'parent_macroponent', 'target_event', 'target_payload_mapping'],
/**
* @param fields {string[]}
* @param noDomain {boolean}
*/
initialize: function(fields, noDomain) {
BuilderToolkitAPIBase.prototype.initialize.call(this, this.TABLE, fields || this.FIELDS, noDomain);
},
/**
* @param addOnEventMappings {addOnEventMappings[]} array of add on event mappings to work on
* @param macroponentSysId {string} sys_id of the macroponent these scripts are tied to
*/
upsertAndDeleteRecords: function(addOnEventMappings = [], macroponentSysId = null) {
// If we have no macroponentSysId, we might accidentally delete the mappings so ABORT
if (!macroponentSysId) {
return;
}
const addOnEventMappingSysIds = addOnEventMappings.map((mapping) => mapping.sysId) ?? [];
const results = [];
const addOnEventMappingGR = this.getRecordsByQuery(`parent_macroponent=${macroponentSysId}`, '', true);
// Make sure we actually found something, then work on those
if (addOnEventMappingGR) {
while (addOnEventMappingGR.next()) {
// If we aren't in the object, we are deleted
if (!addOnEventMappingSysIds.includes(addOnEventMappingGR.getUniqueValue())) {
addOnEventMappingGR.deleteRecord();
}
// Else we need to check for an update and remove from our list of IDs so we know what to create
else {
const currentIdArr = addOnEventMappingSysIds.splice(addOnEventMappingSysIds.indexOf(addOnEventMappingGR.getUniqueValue()), 1);
const currentScript = addOnEventMappings.filter(({
sysId
}) => sysId === currentIdArr[0])[0];
const currentFieldValues = addOnEventMappingGR.getElements().reduce(this.getFieldValues.bind(this), {});
// Let's compare our field values to make sure we don't update needlessly
// If we don't match values, update the record and return the result
for (const field in currentScript) {
if (addOnEventMappingGR.isValidField(field) && currentFieldValues[field] !== currentScript[field]) {
const {
sysId,
...fields
} = currentScript;
this.setFieldValues(addOnEventMappingGR, fields);
results.push(addOnEventMappingGR.update());
break;
}
}
}
}
}
// Now if we have any addOnEventMappingSysIds left, we need to insert
const remainingRecords = addOnEventMappingSysIds.length > 0 ? addOnEventMappings.filter(({
sysId
}) => addOnEventMappingSysIds.includes(sysId)) : null;
if (remainingRecords !== null) {
remainingRecords.forEach(({
sysId,
...fields
}) => {
results.push(this.createRecord({
sysId,
...fields
}));
});
}
return results;
},
type: 'UXAddOnEventMapping'
});
Sys ID
372b14b185721110f877e10cffeb7be0