Copy /**
* Executes a child function corresponding to the object's type property.
* The object is passed to the child function so methods and properties can be overridden.
*
* @param {Object} obj The full class object to be patched.
*/
function hotfix(obj) {
var type = typeof obj === 'function' ? obj.prototype.type || obj.type : obj.type;
if (type && typeof hotfix[type] === 'function') {
hotfix[type](obj);
}
}
hotfix.version = '4.3.1.4';
hotfix.TransactionInbound = function(TransactionInbound) {
TransactionInbound.prototype.prepareForReplay = function prepareForReplay(c) {
c.is_replay = true;
if (c.message.isCreate()) {
c.bond.isNew(true); // for bond condition
}
c.target = c.bond.getTarget();
};
TransactionInbound.prototype.saveSnapshotToStage = function saveSnapshotToStage(c) {
if (c.snapshot) {
c.snapshot.commit();
c.stage.setValue('snapshot', c.snapshot.getUniqueValue());
}
c.stage.commit();
};
};
hotfix.Dataset = function(Dataset) {
Dataset.prototype.getRecords = function getRecords() {
var data = new GlideRecord(this.getValue('table'));
if (this.getElement('advanced') == true) {
this.evaluateAdvancedQuery(data);
} else if (this.hasValue('query_condition')) {
data.addEncodedQuery(this.getValue('query_condition'));
}
if (this.query_start) {
data.addQuery('sys_updated_on', '>', this.query_start);
}
if (this.query_end) {
data.addQuery('sys_updated_on', '<=', this.query_end);
}
if (this.query_from) {
data.addQuery('sys_id', '>=', this.query_from);
}
data.orderBy('sys_id');
data.setLimit(parseInt(this.getValue('max_rows'), 10) + 1);
ws_console.logQuery(data);
this.last_successful_time = this.query_end || new GlideDateTime();
return data;
};
Dataset.prototype.evaluateAdvancedQuery = function evaluateAdvancedQuery(record) {
this._record.query_script += ';true;';
var result = utils.evaluateScript(this.getRecord(), 'query_script', {
current: record,
dataset: this.getRecord()
});
if (result.error) {
throw 'Error evaluating advanced query script: ' + result.error;
}
};
Dataset.execute = function execute(dataset_id, type) {
var dataset = Dataset.getInstance(dataset_id);
var config = dataset.getConfig();
var connection = Connection.getActive(config, dataset.getValue('integration'));
if (!connection.isValidRecord()) {
_console.info('Dataset execution cancelled; no active connection.');
return new DatasetRequest(config);
}
try {
return DatasetRequest.send(dataset, type || "Delta");
} catch (e) {
ActivityLog.setDocument('x_snd_eb_dataset', dataset);
}
};
};
hotfix.DatasetRequest = function(Dataset) {
DatasetRequest.prototype.insertNext = function insertNext(next_id) {
var dataset = this.getDataset();
var request = new DatasetRequest(this.getConfig());
var number, query_end;
request.initialize();
request.setDataset(dataset);
request.setDirection('Outbound');
request.setType(this.getValue('type'));
request.setValue('query_from', next_id);
// show the batch by extending the number
number = this.getValue('number');
number = utils.partialIncrement(number, 1, 1);
request.setValue('number', number);
// prevent infinite exports by fixing the query time
query_end = dataset.isFixedQueryTime() ? new GlideDateTime(this.getValue('query_end')) : new GlideDateTime();
request.setValue('query_start', new GlideDateTime(this.getValue('query_start')));
request.setValue('query_end', query_end);
request.setReady();
request.commit();
return request;
};
};
hotfix.utils = function (utils) {
utils.DEBUG_CORE = _console.DEBUG_TRACE = gs.getProperty('x_snd_eb.snd_console.debug.trace') == 'true';
};
hotfix._console = function(_console) {
_console.PROPERTY_PREFIX = 'x_snd_eb.snd_console.';
_console.DEBUG = gs.getProperty('x_snd_eb.snd_console.debug') == 'true';
_console.DEBUG_TRACE = utils.DEBUG_CORE = gs.getProperty('x_snd_eb.snd_console.debug.trace') == 'true';
_console._wrapFunction = function _wrapFunction(fn, fn_name, options) {
var fn_wrapper;
fn_name = fn_name || _console._getType(fn);
// This function has been wrapped - i.e. prototype inheritance
if (fn.$c_display) {
fn_wrapper = function run_decorated_parent() {
return fn.apply(this, arguments);
};
fn_wrapper.$c_display = fn.$c_display;
if (options.parent_name) {
if (fn_wrapper.$c_display.indexOf(options.parent_name) === 0) {
fn_wrapper.$c_display = '{unknown}~' + fn_wrapper.$c_display;
} else {
fn_wrapper.$c_display = options.parent_name + '~' + fn_wrapper.$c_display;
}
}
return fn_wrapper;
}
fn_wrapper = function run_decorated() {
var name = _console._getName(this, fn_name),
ret, args, scope, e;
if (fn.$c_private) {
name += '#private';
}
try {
args = Array.prototype.slice.call(arguments);
args.unshift(name);
scope = _console.enterScope.apply(_console, args);
scope.inside_try = true; // we are in a try/catch - helps with error reporting
ret = fn.apply(this, arguments);
} catch (ex) {
if (!_console.has_error) {
_console.error(ex, [], name);
_console.has_error = true;
}
_console.leaveScope('[throwing ' + (ex && ex.name ? ex.name : typeof ex) + ']');
throw ex;
}
return _console.leaveScope(ret, fn.$c_private);
};
// store the full name on the function
if (options.parent_name) {
fn_wrapper.$c_display = options.parent_name + (options.is_static ? '::' : '.') + fn_name;
} else {
fn_wrapper.$c_display = fn_name;
}
return fn_wrapper;
};
};
hotfix.Bond = function (Bond) {
Bond.prototype.canCreateTest = function () { return true; };
};
hotfix.BondedAttachment = function (BondedAttachment) {
BondedAttachment.deleteAttachment = function deleteAttachment(attachment_id) {
var grd = new GlideRecord('sys_attachment');
if (grd.get(attachment_id)) {
grd.deleteRecord();
} else {
ws_console.info('Attachment with sys_id %0 not found.', [attachment_id]);
}
};
};
hotfix.Snapshot = function (Snapshot) {
Snapshot.prototype.setOutbound = function setOutbound() {
if (this.isValid()) this.setValue('direction', 'Outbound');
};
Snapshot.prototype.setInbound = function setInbound() {
if (this.isValid()) this.setValue('direction', 'Inbound');
};
};
hotfix.IntegrationComponentList = function (IntegrationComponentList) {
IntegrationComponentList.prototype.getConnections = function getConnections() {
function modifier(grd, item) {
var url;
if (item.direction == 'Inbound') {
item.subtitle = gs.getMessage('Inbound only');
} else if (!grd.endpoint_url.nil()) {
gs.include('URL'); // Overwrite native URL for Yokohama
item.subtitle = new URL(grd.endpoint_url).getHost();
} else {
item.subtitle = gs.getMessage('No endpoint configured');
}
}
return this.getItems('x_snd_eb_connection', 'integration=' + this.integration_id + '^ORDERBYname', modifier);
};
};