We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to write script in ask for approval action in flow designer

SHALIKAS
Tera Guru

I have to write the following script in flow designer for asking approval -

answer = [];
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", current.request.requested_for);
gr.query();
if (gr.next()) {
    var band_level = gr.u_band_level;
    var band = '';
    var number = 0;
    if (gr.vip == false) {
        if (band_level != '') {
            band = band_level.substring(0, 1);
            number = parseInt(band);

        }
        if (gr.u_band_level == '' || number < 3) {
            var id = recursmanager(gr.manager);
            answer.push(id);
        }
    }
}

function recursmanager(ID) {
    var answer = '';
    var user = new GlideRecord('sys_user');
    user.get(ID);
    var band_level_1 = user.u_band_level.toString();
    var band_1 = '';
    var number = 0;
    if (band_level_1 != '') {
        band_1 = band_level_1.substring(0, 1);
        number = parseInt(band);
    }
    if (band_1 >= 3) {
        answer = user.sys_id;
    } else {
        // Move up a level and try again
        answer = recursmanager(user.manager);
    }

    return answer;
}
This script was being used in Advanced section of Ask for approval in workflow. How do I write this in flow designer approval activity
2 REPLIES 2

Amitoj Wadhera
Kilo Sage

Hi @SHALIKAS ,

 

Please find below:

 

return "ApprovesAnyU[6816f79cc0a8016401c5a33be04be441,a8f98bb0eb32010045e1a5115206fe3a]";

Where the square bracket contains sysIds of users.

 

 

AmitojWadhera_0-1714669749427.png

 

 

If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.

 

Regards,

Amitoj

Hii @Amitoj Wadhera 

Where will I write the above script then