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.

Restrict select choice to user in a group

Dawid2
Giga Guru

Hello,

We're currently utilizing script include that pushes choices to one of our Variables based on couple of combinations of other variables. The script is:

getDatabaseTypesBasedOnHostingAndService: function() {
        var databaseTypes = [];

        var hostingType = this.getParameter('sysparm_hosting_type');
        var serviceType = this.getParameter('sysparm_service_type');

        // Handle invalid value combinations.
        if (hostingType == '') return;
        if (hostingType == 'Public' && serviceType == '') return;
        if (hostingType != 'Public' && serviceType != '') return;

        if (serviceType == 'PaaS (Platform as a Service)') {
            databaseTypes.push('Azure');
        } else {
            databaseTypes.push('MSSQL');
            databaseTypes.push('MySQL');
            databaseTypes.push('MongoDB');
            // databaseTypes.push('Oracle');
        }
        if (hostingType == 'Private') {
            databaseTypes.push('Oracle');
            databaseTypes.push('Postgres');
        }
        return JSON.stringify(databaseTypes);
    },

As you can see, the Oracle choice is commented out. What I need is to push Oracle as well but ONLY if currently logged user is a member of group XYZ. Can this code be modified to achieve this? So - if user is a member of group XYZ he will be able to select Oracle, if not - Oracle will not be available for selection on variable.

3 REPLIES 3

Danish Bhairag2
Tera Sage

Hi @Dawid2 ,

 

getDatabaseTypesBasedOnHostingAndService: function() {
        var databaseTypes = [];

        var hostingType = this.getParameter('sysparm_hosting_type');
        var serviceType = this.getParameter('sysparm_service_type');

        // Handle invalid value combinations.
        if (hostingType == '') return;
        if (hostingType == 'Public' && serviceType == '') return;
        if (hostingType != 'Public' && serviceType != '') return;

        if (serviceType == 'PaaS (Platform as a Service)') {
            databaseTypes.push('Azure');
        } else if(gs.getUser().isMemberOf('enter sys id of the group or Group Name')) {
            databaseTypes.push('MSSQL');
            databaseTypes.push('MySQL');
            databaseTypes.push('MongoDB');
            databaseTypes.push('Oracle');
        }else{
databaseTypes.push('MSSQL');
            databaseTypes.push('MySQL');
            databaseTypes.push('MongoDB');
}
        if (hostingType == 'Private') {
            databaseTypes.push('Oracle');
            databaseTypes.push('Postgres');
        }
        return JSON.stringify(databaseTypes);
    },

 

Thanks,

Danish

 

 

 

Danish Bhairag2
Tera Sage

Hi @Dawid2 ,

 

If u want the condition such as if the logged in user is member of some group then only Oracle is available for selection. Please refer below code

 

getDatabaseTypesBasedOnHostingAndService: function() {
        var databaseTypes = [];

        var hostingType = this.getParameter('sysparm_hosting_type');
        var serviceType = this.getParameter('sysparm_service_type');

        // Handle invalid value combinations.
        if (hostingType == '') return;
        if (hostingType == 'Public' && serviceType == '') return;
        if (hostingType != 'Public' && serviceType != '') return;

        if (serviceType == 'PaaS (Platform as a Service)') {
            databaseTypes.push('Azure');
        } else if(gs.getUser().isMemberOf('enter sys id of the group or Group Name')) {// please provide sys id of the grp or group name
            databaseTypes.push('Oracle');
        }else{
            databaseTypes.push('MSSQL');
            databaseTypes.push('MySQL');
            databaseTypes.push('MongoDB');
}
        if (hostingType == 'Private') {
            databaseTypes.push('Oracle');
            databaseTypes.push('Postgres');
        }
        return JSON.stringify(databaseTypes);
    },

 

Thanks,

Danish

 

Thanks for both suggestions, Danish. I'll try to test it out but I can't believe it was that easy 🙂