Name

sn_hr_er.er_ProducerBase

Description

Base class of methods used for Employee Relations record producers. Edit script include er_Producer to override specific methods or add custom functionality.

Script

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);
  * @param current GlideRecord [sn_hr_er_case] The ER case 
  * @param producer Object Contains information from the record producer
  * @param 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'.
  * @param current GlideRecord representing the ER case
  * @param producer Object Contains information from the record producer
  * @param 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'
};

Sys ID

9d65b753ff270010a9e7faf9453bf18e

Offical Documentation

Official Docs: