Override addInvolvedPeople Function from read only class er_ProducerBase
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2023 03:56 AM - edited 12-27-2023 03:59 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
01-03-2024 02:19 PM - edited 01-03-2024 02:33 PM
My suggestion would be not to override this script include in the way mentioned above.
What happens if the
if (rpID != "6f14bbe51b5fed545ed35533604bcbcd") {
//nothing will happen
}
if (rpID == "6f14bbe51b5fed545ed35533604bcbcd") {
// your code will work
}
for all the other record producers the _addInvolvedPeople function will simply not work.
I think you should create a separate script include in the employee relations scope and use the below code to achieve your custom functionality. Add the below lines in the "What it will contain section on the record producer in the script field".
The first line will create the case with the right variables mapped.
The second line will achieve your needs if the custom script include is coded correctly.
new sn_hr_core.hr_ServicesUtil(current).createCaseFromProducer(producer, recordProducerId);
new sn_hr_er.custom_scriptInclude().customScriptIncludeFunction(current, producer, recordProducerID)
Also check if there are any restricted caller access privileges in the denied state for the ER scope or the RP scope.
The er_Producer script includes caller access setting is caller restriction.
Also can you confirm if the choice value of "impacted_employee" has been added to the type field on the ER table. I do not see it in OOTB instance.
Mark helpful if this helped.
Thanks,