Multiple approval request based on List collector choices

Sue143
Tera Expert

Hi guys,

I am trying to build a script that would generate multiple approval requests according the user selection of a list collector variable type. What I have so far, is generating all the approval requests at once, so what I need is to the script identify what has been selected and only generate the approval request for those selections.

See the script below:

answer = myScript();

function myScript() {

    var selectedoption = [];

    var collector = current.variables.variablename.toString();

    var list = collector.split(",");


    for (var i = 0; i < list.length; i++) {


        var gr = new GlideRecord('question_choice');

        gr.addQuery('question.sys_id=NUMBEROFSYSID');


        if (gr.get(list[i] == "SYSID")) { //sys ID of plant1

            selectedoption.push('SYSID'); //sys ID of user1

        }
        if (gr.get(list[i] == "SYSID")) { //sys ID of plant2

            selectedoption.push('SYSID'); //sys ID of user2

        }
        if (gr.get(list[i] == "SYSID")) { //sys ID of plant3

            selectedoption.push('SYSID'); //sys ID of user3

        }
        if (gr.get(list[i] == "SYSID" || gr.get(list[i] == "SYSID"))) { //sys ID of Plant4 and plant5

            selectedoption.push('SYSID'); //sys ID of user4

        }

        if (gr.next()) {

            return selectedoption;
        }
    }
}

 

Thank you, appreciate any help.

2 REPLIES 2

Community Alums
Not applicable

Hi @suellen ,

You can use a Flow for this , refer to this :https://community.servicenow.com/community?id=community_Blog&sys_id=9379ad701b0c05d056b699b8bd4bcb02

Mark my answer correct & Helpful, if Applicable.

Thanks,
Sandeep

Hi @Sandeep Dutta at my company we use Flow for specific situations, not in this case. But thank you. 🙂