How to map variables in a variable set with backend HR case table fields without using RP script

vijani
Tera Expert

How can I map variables in a variable set to fields in the backend HR case table without using a Record Producer script?

We have a variable set called "HR Information," which includes the following variables: Subject Person, Opened For, Watch List, Collaborator, Priority, Description, and Short Description. Whenever we submit the related variable set Record Producer, the values from the variable set should be mapped to the corresponding fields in the backend HR case table using out-of-the-box (OOB) functionality.

new sn_hr_core.hr_ServicesUtil(current, gs).createCaseFromProducer(producer, cat_item.sys_id)

  

1 REPLY 1

vijani
Tera Expert

By adding a new function to the OOB (hr_CaseUtils) script include, we can achieve this requirement.

Newly updated script lines are highlighted with red 

 

var hr_CaseUtils = Class.create();
hr_CaseUtils.prototype = {
    initialize : function(_case, _gs) {
        if (!_case)
            return;

        this._case = _case;
        this._gs = _gs || gs;

        // Other object scripts have a reference here as they are used throughout
        this.hrProfile = new hr_Profile(this._case.hr_profile, this._gs);
        this.hrUtils = new hr_Utils();

        this._ignoreFields = {
            'opened_for' : '',
            'priority' : '',
            'short_description' : '',
            'description' : ''
        };
        this._requiresUserOrProfileCreation = {
            'request_onboarding':'',
            'new_hire_journey':''
        };
    },

    populateCase : function(service, questions, source) {
        var hrServiceGr = new GlideRecord(hr.TABLE_SERVICE);
        if (hrServiceGr.get(service) && hrServiceGr.getValue('active')) {
            var serviceName = hrServiceGr.getValue('name');
            var serviceValue = hrServiceGr.getValue('value');

            this._logDebug("Creating new HR Case record for service name: " + serviceName);

            this._setServiceFields(hrServiceGr);
            this._setGeneralFields(serviceValue, questions);
            this._setCommonFields(hrServiceGr, questions, source);
            this._mapVariableSetFields(questions);

            var extPoints = new GlideScriptedExtensionPoint().getExtensions('sn_hr_core.HRPopulateCaseFields');
            for(var i = 0; i < extPoints.length; i++) {
                if (extPoints[i].handles(hrServiceGr))
                    extPoints[i].setFields(hrServiceGr,  this._case);
            }
        }
    },
    /*
    * Updates the variable set fields into the Case.
    */
    _mapVariableSetFields: function(questions) {
    var parameters = this._getParametersFromQuestions(questions);
    var notes = parameters['comments_and_work_notes'];
    this._logDebug("Parameters mapped from questions: " + JSON.stringify(parameters));

    // Map values from the variable set to the HR case fields

    if (notes) {
        this._case.work_notes = notes;
    }
    if (parameters['subject_person']) {
        this._case.subject_person = parameters['subject_person'];
    }
    if (parameters['opened_for']) {
        this._case.opened_for = parameters['opened_for'];
    }
    if (parameters['watch_list']) {
        this._case.watch_list = parameters['watch_list'];
    }
    if (parameters['collaborator']) {
        this._case.collaborator = parameters['collaborator'];
    }
    if (parameters['priority']) {
        this._case.priority = parameters['priority'];
    }
    if (parameters['description']) {
        this._case.description = parameters['description'];
    }
    if (parameters['short_description']) {
        this._case.short_description = parameters['short_description'];
    }
},
    /*
    * Updates the service and service offering fields into the Case.
    */