Improved method of wrapping.
#FA-8, #FA-10
This commit is contained in:
@ -25,11 +25,11 @@ LogUtils.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
write: function(message, options){
|
||||
write: function(message, options = {}){
|
||||
var {
|
||||
type = "info",
|
||||
timestamp = new Date(),
|
||||
funcName = "Unknown",
|
||||
funcName = "",
|
||||
currentRecord = current
|
||||
} = options;
|
||||
|
||||
|
||||
@ -8,52 +8,51 @@
|
||||
<description/>
|
||||
<name>ProcessorUtils</name>
|
||||
<script><![CDATA[var _source;
|
||||
var _appScope;
|
||||
|
||||
var ProcessorUtils = Class.create();
|
||||
ProcessorUtils.prototype = {
|
||||
initialize: function(options) {
|
||||
var { table, scope, name } = options;
|
||||
if(table) this.setSource(options.table, {scope, name});
|
||||
initialize: function(appScope) {
|
||||
if(!appScope)
|
||||
new LogUtils().write("Application scope is not received.", {type: "error", funcName: "initialize"});
|
||||
|
||||
_appScope = appScope;
|
||||
},
|
||||
|
||||
setSource: function(table, options){
|
||||
var { scope, name } = options;
|
||||
wrapScriptInclude: function(scriptPrototype, options = {}){
|
||||
var {
|
||||
table = "sys_script_include",
|
||||
name = scriptPrototype.type,
|
||||
sys_id = false
|
||||
} = options;
|
||||
|
||||
var sourceGr = new GlideRecord(table);
|
||||
sourceGr.addQuery("name", name);
|
||||
sourceGr.addQuery("sys_scope.scope", scope);
|
||||
sourceGr.query();
|
||||
if(sourceGr.next()){
|
||||
_source = sourceGr;
|
||||
}
|
||||
},
|
||||
|
||||
wrapper: function(scopedClass){
|
||||
Object.getOwnPropertyNames(scopedClass).forEach(function(f) {
|
||||
if(Object.getOwnPropertyDescriptor(scopedClass,f).writable){
|
||||
if (typeof scopedClass[f] === 'function') {
|
||||
var old = scopedClass[f];
|
||||
var sourceRecord = this.getSourceRecord(table, { name, sys_id });
|
||||
|
||||
Object.getOwnPropertyNames(scriptPrototype).forEach(function(f) {
|
||||
if(Object.getOwnPropertyDescriptor(scriptPrototype,f).writable){
|
||||
if (typeof scriptPrototype[f] === 'function') {
|
||||
var old = scriptPrototype[f];
|
||||
var funcName = f.toString();
|
||||
if(_source){
|
||||
var sourceTable = _source.getTableName();
|
||||
var sourceID = _source.getValue("sys_id");
|
||||
}
|
||||
scopedClass[f] = function() {
|
||||
scriptPrototype[f] = function() {
|
||||
functionName = Symbol(funcName);
|
||||
var returnValue = false;
|
||||
try{
|
||||
if(old == undefined) throw new Error("Function: " + funcName + " does not exist");
|
||||
returnValue = old.apply(this, arguments);
|
||||
}catch(err){
|
||||
var func = funcName ? "Function: " + funcName : undefined;
|
||||
var message = err.message ? "Message: " +err.message : undefined;
|
||||
var line = err.lineNumber ? "Line: " + err.lineNumber : undefined;
|
||||
|
||||
|
||||
var options = {
|
||||
type: "error",
|
||||
funcName: funcName
|
||||
funcName: funcName,
|
||||
lineNumber: line
|
||||
};
|
||||
new LogUtils().write("message", options);
|
||||
new LogUtils().write(message, options);
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
@ -62,6 +61,19 @@ ProcessorUtils.prototype = {
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
getSourceRecord: function(table, options){
|
||||
var { sys_id, name } = options;
|
||||
|
||||
var sourceGr = new GlideRecord(table);
|
||||
if(name) sourceGr.addQuery("name", name);
|
||||
if(sys_id) sourceGr.addQuery("sys_id", sys_id);
|
||||
sourceGr.addQuery("sys_scope.scope", _appScope);
|
||||
sourceGr.query();
|
||||
if(sourceGr.next()){
|
||||
_source = sourceGr;
|
||||
}
|
||||
},
|
||||
|
||||
type: 'ProcessorUtils'
|
||||
};]]></script>
|
||||
|
||||
@ -14,14 +14,18 @@ QueueUtils.prototype = {
|
||||
|
||||
writeToQueue: function(event, data){
|
||||
gs.info('writer');
|
||||
this.tester();
|
||||
new LogUtils().write("finished function",{ type: "debug", funcName: "writeToQueue" });
|
||||
},
|
||||
|
||||
tester: function(){
|
||||
new LogUtils().write("tester",{ type: "debug", funcName: "tester" });
|
||||
},
|
||||
|
||||
type: 'QueueUtils'
|
||||
};
|
||||
|
||||
|
||||
new ProcessorUtils({table: "sys_script_include", scope: "x_355681_fa", name: "QueueUtils"})
|
||||
.wrapper(QueueUtils.prototype);]]></script>
|
||||
new ProcessorUtils("x_355681_fa").wrapScriptInclude(QueueUtils.prototype);]]></script>
|
||||
<sys_class_name>sys_script_include</sys_class_name>
|
||||
<sys_created_by>admin</sys_created_by>
|
||||
<sys_created_on>2023-01-13 22:09:49</sys_created_on>
|
||||
|
||||
@ -2,18 +2,63 @@
|
||||
<sys_ui_list parent="" relationship="" sys_domain="global" table="x_355681_fa_log" version="2" view="">
|
||||
<sys_ui_list_element action="INSERT_OR_UPDATE">
|
||||
<average_value>false</average_value>
|
||||
<element>sys_created_on</element>
|
||||
<list_id display_value="x_355681_fa_log" element="NULL" name="x_355681_fa_log" parent="NULL" relationship="NULL" sys_domain="global" view="Default view">9a1af9369700211093a8337e6253af71</list_id>
|
||||
<element>impacted_record</element>
|
||||
<list_id display_value="x_355681_fa_log" element="NULL" name="x_355681_fa_log" parent="NULL" relationship="NULL" sys_domain="global" view="Default view">120c4307971021105838bfb3f153afe3</list_id>
|
||||
<max_value>false</max_value>
|
||||
<min_value>false</min_value>
|
||||
<position>0</position>
|
||||
<sum>false</sum>
|
||||
<sys_created_by>admin</sys_created_by>
|
||||
<sys_created_on>2023-01-01 10:02:08</sys_created_on>
|
||||
<sys_id>121af9369700211093a8337e6253af73</sys_id>
|
||||
<sys_created_on>2023-01-14 20:54:17</sys_created_on>
|
||||
<sys_id>1a0c4307971021105838bfb3f153afe4</sys_id>
|
||||
<sys_mod_count>0</sys_mod_count>
|
||||
<sys_updated_by>admin</sys_updated_by>
|
||||
<sys_updated_on>2023-01-01 10:02:08</sys_updated_on>
|
||||
<sys_updated_on>2023-01-14 20:54:17</sys_updated_on>
|
||||
</sys_ui_list_element>
|
||||
<sys_ui_list_element action="INSERT_OR_UPDATE">
|
||||
<average_value>false</average_value>
|
||||
<element>message</element>
|
||||
<list_id display_value="x_355681_fa_log" element="NULL" name="x_355681_fa_log" parent="NULL" relationship="NULL" sys_domain="global" view="Default view">120c4307971021105838bfb3f153afe3</list_id>
|
||||
<max_value>false</max_value>
|
||||
<min_value>false</min_value>
|
||||
<position>1</position>
|
||||
<sum>false</sum>
|
||||
<sys_created_by>admin</sys_created_by>
|
||||
<sys_created_on>2023-01-14 20:54:17</sys_created_on>
|
||||
<sys_id>de0c4307971021105838bfb3f153afe4</sys_id>
|
||||
<sys_mod_count>0</sys_mod_count>
|
||||
<sys_updated_by>admin</sys_updated_by>
|
||||
<sys_updated_on>2023-01-14 20:54:17</sys_updated_on>
|
||||
</sys_ui_list_element>
|
||||
<sys_ui_list_element action="INSERT_OR_UPDATE">
|
||||
<average_value>false</average_value>
|
||||
<element>timestamp</element>
|
||||
<list_id display_value="x_355681_fa_log" element="NULL" name="x_355681_fa_log" parent="NULL" relationship="NULL" sys_domain="global" view="Default view">120c4307971021105838bfb3f153afe3</list_id>
|
||||
<max_value>false</max_value>
|
||||
<min_value>false</min_value>
|
||||
<position>2</position>
|
||||
<sum>false</sum>
|
||||
<sys_created_by>admin</sys_created_by>
|
||||
<sys_created_on>2023-01-14 20:54:17</sys_created_on>
|
||||
<sys_id>520c4307971021105838bfb3f153afe5</sys_id>
|
||||
<sys_mod_count>0</sys_mod_count>
|
||||
<sys_updated_by>admin</sys_updated_by>
|
||||
<sys_updated_on>2023-01-14 20:54:17</sys_updated_on>
|
||||
</sys_ui_list_element>
|
||||
<sys_ui_list_element action="INSERT_OR_UPDATE">
|
||||
<average_value>false</average_value>
|
||||
<element>sys_created_on</element>
|
||||
<list_id display_value="x_355681_fa_log" element="NULL" name="x_355681_fa_log" parent="NULL" relationship="NULL" sys_domain="global" view="Default view">120c4307971021105838bfb3f153afe3</list_id>
|
||||
<max_value>false</max_value>
|
||||
<min_value>false</min_value>
|
||||
<position>3</position>
|
||||
<sum>false</sum>
|
||||
<sys_created_by>admin</sys_created_by>
|
||||
<sys_created_on>2023-01-14 20:54:17</sys_created_on>
|
||||
<sys_id>d20c4307971021105838bfb3f153afe5</sys_id>
|
||||
<sys_mod_count>0</sys_mod_count>
|
||||
<sys_updated_by>admin</sys_updated_by>
|
||||
<sys_updated_on>2023-01-14 20:54:17</sys_updated_on>
|
||||
</sys_ui_list_element>
|
||||
<sys_ui_list action="INSERT_OR_UPDATE">
|
||||
<average_value>false</average_value>
|
||||
@ -27,10 +72,10 @@
|
||||
<sum>false</sum>
|
||||
<sys_class_name>sys_ui_list</sys_class_name>
|
||||
<sys_created_by>admin</sys_created_by>
|
||||
<sys_created_on>2023-01-01 10:02:08</sys_created_on>
|
||||
<sys_created_on>2023-01-14 20:54:17</sys_created_on>
|
||||
<sys_domain>global</sys_domain>
|
||||
<sys_domain_path>/</sys_domain_path>
|
||||
<sys_id>9a1af9369700211093a8337e6253af71</sys_id>
|
||||
<sys_id>120c4307971021105838bfb3f153afe3</sys_id>
|
||||
<sys_name>x_355681_fa_log</sys_name>
|
||||
<sys_package display_value="Fulfilment Automater" source="x_355681_fa">c04afa629713111093a8337e6253af6d</sys_package>
|
||||
<sys_policy/>
|
||||
|
||||
Reference in New Issue
Block a user