Restrict select choice to user in a group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2023 04:16 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2023 04:27 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2023 04:30 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2023 04:34 AM
Thanks for both suggestions, Danish. I'll try to test it out but I can't believe it was that easy 🙂