Override function from ready only class
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2023 04:02 AM
We are trying to override a function(_addInvolvedPeople) from er_ProducerBase
var er_ProducerBase = Class.create(); er_ProducerBase.prototype = { initialize: function() { }, /** * Create an ER case from a record producer. Called from a record producer script like: * new er_ProducerBase().createCaseFromProducer(current, producer, cat_item.sys_id); * current GlideRecord [sn_hr_er_case] The ER case * producer Object Contains information from the record producer * recordProducerId Id of the sc_cat_item_producer record */ createCaseFromProducer: function(current, producer, recordProducerId) { new sn_hr_core.hr_ServicesUtil(current).createCaseFromProducer(producer, recordProducerId); this._addInvolvedPeople(current, producer, recordProducerId); }, /** * Insert the users specified in the multi row table on the catalog item into the involved party table, using * default type of 'other'. * current GlideRecord representing the ER case * producer Object Contains information from the record producer * rpId Id of the sc_cat_item_producer record */ _addInvolvedPeople: function(current, producer, rpId) { var relevantVariables = new global.HRSecurityUtils().getRelevantVariablesForCatItem(rpId); var seenUsers = {}; // Look for multi row table in catalog item with 'involved_user' variables for (var i = 0; i < relevantVariables.length; i++) { var variable = relevantVariables[i]; if (variable.type == 'sc_multi_row') { var multiVarArray = JSON.parse(producer[variable.name]); for (var j = 0; j < multiVarArray.length; j++) { var dataObj = multiVarArray[j]; if (dataObj.hasOwnProperty('involved_user') && !seenUsers.hasOwnProperty(dataObj['involved_user'])) { var userId = dataObj['involved_user']; seenUsers[userId] = true; var grParty = new GlideRecord('sn_hr_er_involved_party'); grParty.setValue('hr_case', current.getUniqueValue()); grParty.setValue('user', userId); grParty.setValue('type', 'other'); grParty.setWorkflow(false); grParty.insert(); } } break; } } }, type: 'er_ProducerBase' };
where we want in case of Reorg Support record producer we want the involved party record for involved_user multi row set to be created with type other impacted_employee.
i updated the class(er_Producer) which is extending this base class(er_ProducerBase), as given below
var er_Producer = Class.create(); er_Producer.prototype = Object.extendsObject(sn_hr_er.er_ProducerBase, { _addInvolvedPeople: function(current, producer, rpId) { var relevantVariables = new global.HRSecurityUtils().getRelevantVariablesForCatItem(rpId); var seenUsers = {}; // Look for multi row table in catalog item with 'involved_user' variables if (rpID == "6f14bbe51b5fed545ed35533604bcbcd") { for (var i = 0; i < relevantVariables.length; i++) { var variable = relevantVariables[i]; if (variable.type == 'sc_multi_row') { var multiVarArray = JSON.parse(producer[variable.name]); for (var j = 0; j < multiVarArray.length; j++) { var dataObj = multiVarArray[j]; if (dataObj.hasOwnProperty('involved_user') && !seenUsers.hasOwnProperty(dataObj['involved_user'])) { var userId = dataObj['involved_user']; seenUsers[userId] = true; var grParty = new GlideRecord('sn_hr_er_involved_party'); grParty.setValue('hr_case', current.getUniqueValue()); grParty.setValue('user', userId); grParty.setValue('type', 'impacted_employee'); grParty.setWorkflow(false); grParty.insert(); } } break; } } } }, type: 'er_Producer' }); // Object.extendsObject only clones prototype from parent class // Clone missing non-prototype properties from parent class (function() { for (var property in sn_hr_er.er_ProducerBase) if (!er_Producer.hasOwnProperty(property)) er_Producer[property] = sn_hr_er.er_ProducerBase[property]; })();
However the involved party record is not even getting created for the case.
Can someone point out where am I going wrong?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2023 04:16 PM
The script uses an undefined variable in the if's condition.
rpID (which is not defined) is not the same as rpId (which is defined as it is one of the method's parameters).
But there might be a logical problem too with your modification: are you sure you want adding the involved party to only run for this single record producer?
If not, you need to move the if so that it only conditions line
grParty.setValue('type', 'impacted_employee');
and not the whole block that adds involved parties.
This modification will have global effects and - if left as is - will basically no longer run for any other record producer.
Perhaps what you want is:
_addInvolvedPeople: function(current, producer, rpId) {
var relevantVariables = new global.HRSecurityUtils().getRelevantVariablesForCatItem(rpId);
var seenUsers = {};
// Look for multi row table in catalog item with 'involved_user' variables
for (var i = 0; i < relevantVariables.length; i++) {
var variable = relevantVariables[i];
if (variable.type == 'sc_multi_row') {
var multiVarArray = JSON.parse(producer[variable.name]);
for (var j = 0; j < multiVarArray.length; j++) {
var dataObj = multiVarArray[j];
if (dataObj.hasOwnProperty('involved_user') && !seenUsers.hasOwnProperty(dataObj['involved_user'])) {
var userId = dataObj['involved_user'];
seenUsers[userId] = true;
var grParty = new GlideRecord('sn_hr_er_involved_party');
grParty.setValue('hr_case', current.getUniqueValue());
grParty.setValue('user', userId);
// if moved and corrected
if (rpId == "6f14bbe51b5fed545ed35533604bcbcd") {
grParty.setValue('type', 'impacted_employee');
}
else {
grParty.setValue('type', 'other');
}
grParty.setWorkflow(false);
grParty.insert();
}
}
break;
}
}
},