Dinesh Kumar11
Kilo Sage
Kilo Sage

Requirement : 

Trigger different approvals based on the choice selected in the choice list variable. The approval data information is stored in custom data table which is easy to modify and maintain. 

Solution : One common workflow has to be built which reads the approval information from the custom table for the choice selected and trigger the approvals accordingly. 
Components :

1) Build a custom table and store the below values .

a) Catalog Item Name  (String column)

b) Variable Label and Name (String column)

c) Choice Label and Name (String column)

d) List of approvals  (List)

Please refer the below screenshot of sample record :

 

find_real_file.png

 

2) Create a child workflow which reads the records from the custom table based on the choice selected and triggers approval to approvers stored in "Group" field in custom table.

find_real_file.png

 

Script used in Approval Group activity is as below : 

var answer = [];
var groups_app = [];
var ques = '';
var question_choice = '';
var ans = '';
var gr = new GlideRecord('u_custom_table');
gr.addEncodedQuery('u_index_2=' + current.cat_item.getDisplayValue()+"^"+'u_index_1=' + "Catalog Approval Mappings");
gr.query();
while (gr.next()) {
    ques = gr.u_string_1;
    ans = gr.u_string_4;
    groups_app = gr.u_groups.toString().split(',');
    var gr1 = new GlideRecord('sc_item_option_mtom');
    gr1.addEncodedQuery('request_item=' + current.sys_id);
    gr1.query();
    while (gr1.next()) {
        var valu = gr1.sc_item_option.item_option_new.getDisplayValue();
        if (valu == ques) {
            var gr2 = new GlideRecord('sc_item_option');
            gr2.addEncodedQuery('value=' + ans);
            gr2.addEncodedQuery('sys_id=' + gr1.sc_item_option);
            gr2.query();
            if (gr2.next()) {
                if (ques == gr2.item_option_new.getDisplayValue()) {
                    if (ans == gr2.value.getDisplayValue()) {
                        if (groups_app != '') {
                            var getapprovers = new GlideRecord('sys_user_grmember');
                            getapprovers.addQuery('group', groups_app);
                            getapprovers.query();
                            while (getapprovers.next()) {
                                for (var i = 0; i < groups_app.length; i++) {
                                    answer.push(groups_app[i]);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

 

3) Create a workflow for specific catalog item and call the above child workflow for triggering approvals. 

 

find_real_file.png

 

Hope you will find it as helpful. Don’t forget to Mark it Helpful and Bookmark article so you can easily find on your profile.

Thank you,
Dinesh Kumar Raghu,
Capgemini India Pvt Ltd.

GmailID : dineshkumar.raghu9426@gmail.com

Comments
k shiva1
Tera Contributor

Hi Dinesh,

Your explanation is very useful, I love this type work.
If posible can you provide the update set for this work. 

Thanks,
Shiva.

Version history
Last update:
‎04-07-2022 03:17 AM
Updated by: