Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Dynamic approvals in record producer

Hafsa1
Mega Sage

I have created RP in "sc_cat_item_producer" table with some variables in CSM module.

In variables there are two variables (department and tower).

I have a list of approval matrix for which I have created custom table(u_tower_matrix) with 3 fields (department, tower and approver).

I want, based on department and tower selected while raising case approval should trigger based on apporval matrix.

How I can achieve it?

3 REPLIES 3

Runjay Patel
Giga Sage

Hi @Hafsa1 ,

 

yo can create flow on csm table.

Add activity call lookup record, put condition for department  and tower, which will return 1 record. 

Add next activity ask for approval and the n approval group get it from lookup record from above step.

 

Accept and like the solution if it helped

In table "u_tower_matrix", combination is based on variables which user select while raising case. IT's dynamic.

 

yuvarajkate
Giga Guru

You can do this using Script Include and Business Rule,

Create a Business Rule on the sc_cat_item_producer table to trigger when a record is created or updated. The Business Rule will fetch the approver(s) from the u_tower_matrix table and assign the approval dynamically.

 

Script Include:

var GetTowerMatrixApprovers = Class.create();
GetTowerMatrixApprovers.prototype = {
    initialize: function() {},

    getApprovers: function(department, tower) {
        var approvers = [];
        var gr = new GlideRecord('u_tower_matrix'); 
        gr.addQuery('department', department);
        gr.addQuery('tower', tower);
        gr.query();

        while (gr.next()) {
            approvers.push(gr.approver.toString());
        }

        return approvers;
    },

    type: 'GetTowerMatrixApprovers'
};

 

Business Rule:

When to run: After Insert

(function executeRule(current, previous /*null when async*/) {
   var approvers = new GetTowerMatrixApprovers().getApprovers(current.department, current.tower);

    if (approvers.length > 0) {
        var gr = new GlideRecord('sysapproval_approver');
        for (var i = 0; i < approvers.length; i++) {
            gr.initialize();
            gr.sysapproval = current.sys_id;
            gr.approver = approvers[i]; 
            gr.state = 'requested'; 
            gr.insert();
        }
    } else {
        gs.addErrorMessage('No approvers found for the selected Department and Tower.');
    }
})(current, previous);