Calling a Script Include in a Flow Designer

sam352120
Kilo Guru

Hey Everyone,

I am trying to call a script include in the flow designer and the logic implemented here is based on the country selected

,the assignment group will be set for the catalog task accordingly.

Script Include:

------------------

Name-EXPClientOnboardUtils

Scope- Global

Script:

--------

var EXPClientOnboardUtils = Class.create();
EXPClientOnboardUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

CSMAssignmentGroupMappings: [
{country: 'Australia', assignment_group: 'd59f25ecdb48fb88bdb1317ffe9619ed'},
{country: 'New Zealand', assignment_group: 'd59f25ecdb48fb88bdb1317ffe9619ed'},
{country: 'Brazil', assignment_group: 'c0e07354dba5485824b89e57f4961962'},
{country: 'Colombia', assignment_group: 'a239e22edb75d01878ce794039961903'},
{country: 'India', assignment_group: 'd59f25ecdb48fb88bdb1317ffe9619ed'},
{country: 'Singapore', assignment_group: 'd59f25ecdb48fb88bdb1317ffe9619ed'},
{country: 'Netherlands', assignment_group: '9f99af38db74d8d8ad91fbf9f4961925'},
{country: 'Spain', assignment_group: '0da7e7e0dbb2c09cad91fbf9f49619d4'},
{country: 'United Kingdom', assignment_group: 'f80ea82edb1ee380ac273f3ffe9619d2'},
{country: 'Ireland', assignment_group: 'f80ea82edb1ee380ac273f3ffe9619d2'}
],

CSSAssignmentGroupMappings: [
{country: 'Australia', assignment_group: '6b47d6f9db069fc4216b3f3ffe961951'},
{country: 'New Zealand', assignment_group: '6b47d6f9db069fc4216b3f3ffe961951'},
{country: 'Brazil', assignment_group: 'a84bfa83db190414aebd0578f49619bc'},
{country: 'Colombia', assignment_group: 'a239e22edb75d01878ce794039961903'},
{country: 'India', assignment_group: '6b47d6f9db069fc4216b3f3ffe961951'},
{country: 'Netherlands', assignment_group: 'dce3b701db78d49c7d5992c9f49619b6'},
{country: 'Singapore', assignment_group: '6b47d6f9db069fc4216b3f3ffe961951'},
{country: 'Spain', assignment_group: 'ea01c941db3ec05c7d5992c9f4961908'},
{country: 'United Kingdom', assignment_group: '3940f263db0e6b08615e317ffe9619d1'},
{country: 'Ireland', assignment_group: '3940f263db0e6b08615e317ffe9619d1'}

],
ApproverAssignmentGroupMappings: [
{country: 'Australia', assignment_group: 'bf8e8f191b63c590ac35b8c2cd4bcb39'},
{country: 'New Zealand', assignment_group: 'bf8e8f191b63c590ac35b8c2cd4bcb39'},
{country: 'Brazil', assignment_group: '8ac60ea31b260d10323939f4464bcb6c'},
{country: 'Netherlands' , assignment_group: 'b5b8527b1b93411409a339f4464bcbb6'},
{country: 'Singapore', assignment_group: 'bf8e8f191b63c590ac35b8c2cd4bcb39'},
{country: 'Spain', assignment_group: '40b8da7f1b5b0114920639f4464bcb43'}

],

getAssignmentGroup: function(country,type){
var assignmentGroup = '';
var assignmentGroupMappings = '';
switch(type){
case 'CSM':
assignmentGroupMappings = this.CSMAssignmentGroupMappings;
break;
case 'CSS':
assignmentGroupMappings = this.CSSAssignmentGroupMappings;
break;
case 'Approval':
assignmentGroupMappings = this.ApproverAssignmentGroupMappings;
break;

}
assignmentGroupMappings.forEach(function(obj){
if(country == obj.country)
assignmentGroup = obj.assignment_group;
});
return assignmentGroup;
},

type: 'EXPClientOnboardUtils'
});

 

Based on the country type (CSM/CSS/Assignmnet group) the catalog tasks will be assigned to the appropriate 

assignment group.

Flow Designer:

find_real_file.png

 

Please do let me know how we can call and assign to different assignment groups through the flow designer.

Thanks in Advance,

Sambit

7 REPLIES 7

Aman Kumar S
Kilo Patron

Its the usual way:

new ScriptInlcude().functionName(parameters);

Best Regards
Aman Kumar

Marc Mouries
ServiceNow Employee
ServiceNow Employee

This is a bad design pattern. Use a decision table instead. Your customer will thank you.

Creator Toolbox - Decision Builder with Julia Perlis

 

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Sam352120,

1. As Marc replied, it'll be better to use decision table or at least rewrite the Script Include as below.

var EXPClientOnboardUtils = Class.create();
EXPClientOnboardUtils.prototype = {
    initialize: function() {},
    getAssignmentGroup: function(country, type) {
        var assignmentGroupMappings = {
            "CSM": {
                "Australia": "d59f25ecdb48fb88bdb1317ffe9619ed",
                "New Zealand": "d59f25ecdb48fb88bdb1317ffe9619ed",
                "Brazil": "c0e07354dba5485824b89e57f4961962",
                "Colombia": "a239e22edb75d01878ce794039961903",
                "India": "d59f25ecdb48fb88bdb1317ffe9619ed",
                "Singapore": "d59f25ecdb48fb88bdb1317ffe9619ed",
                "Netherlands": "9f99af38db74d8d8ad91fbf9f4961925",
                "Spain": "0da7e7e0dbb2c09cad91fbf9f49619d4",
                "United Kingdom": "f80ea82edb1ee380ac273f3ffe9619d2",
                "Ireland": "f80ea82edb1ee380ac273f3ffe9619d2"
            },
            "CSS": {
                "Australia": "6b47d6f9db069fc4216b3f3ffe961951",
                "New Zealand": "6b47d6f9db069fc4216b3f3ffe961951",
                "Brazil": "a84bfa83db190414aebd0578f49619bc",
                "Colombia": "a239e22edb75d01878ce794039961903",
                "India": "6b47d6f9db069fc4216b3f3ffe961951",
                "Netherlands": "dce3b701db78d49c7d5992c9f49619b6",
                "Singapore": "6b47d6f9db069fc4216b3f3ffe961951",
                "Spain": "ea01c941db3ec05c7d5992c9f4961908",
                "United Kingdom": "3940f263db0e6b08615e317ffe9619d1",
                "Ireland": "3940f263db0e6b08615e317ffe9619d1"
            },
            "Approval": {
                "Australia": "bf8e8f191b63c590ac35b8c2cd4bcb39",
                "New Zealand": "bf8e8f191b63c590ac35b8c2cd4bcb39",
                "Brazil": "8ac60ea31b260d10323939f4464bcb6c",
                "Netherlands": "b5b8527b1b93411409a339f4464bcbb6",
                "Singapore": "bf8e8f191b63c590ac35b8c2cd4bcb39",
                "Spain": "40b8da7f1b5b0114920639f4464bcb43"
            }
        };
        var assignmentGroup = assignmentGroupMappings[type][country];
        return assignmentGroup;
    },
    type: 'EXPClientOnboardUtils'
};

2. I'll create an Action in Flow Designer to call Script Include

1.1 Inputs

find_real_file.png

1.2 Script Step

find_real_file.png

1.3 Outputs

find_real_file.png

 3. Flow. Call the created Action to get Assignment Group.

find_real_file.png

Thank you for your detailed response, @Hitoshi Ozawa! This is exactly what I was looking for in my research. Best response! 👍🙌