- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2023 12:19 AM
Dear knowledge wizards 🙂
I need a little scripting help!
I have found this script in another article but I need it "refitted" for my needs and I am bad at scripting ;D
Instead of the script checking for which country I need it to check which assignment group the user is in:
I have attached the script in .txt file
Thank you in advance 🙂
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 12:49 AM
Hi @Susanne Bredal ,
Below is the non-tested modified script you can give a try.
checkCondition();
function checkCondition() {
var currentUserID = gs.getUserID(); // Get the ID of the current user
var currentUser = new GlideRecord('sys_user'); // Create a GlideRecord object for the current user
currentUser.get(currentUserID); // Load the current user's record
var groupName = "My Assignment Group"; // Replace this with the name of the assignment group you want to check for
var assignmentGroups = currentUser.getMyGroups(); // Get an array of the current user's assignment groups
for (var i = 0; i < assignmentGroups.length; i++) {
var assignmentGroup = assignmentGroups[i].name.toString(); // Convert the assignment group name to a string
if (assignmentGroup == groupName) {
// If the user is a member of the specified assignment group, return false (meaning the item is available)
return false;
}
}
// If the user is not a member of the specified assignment group, return true (meaning the item is not available)
return true;
}
This script checks if the current user is a member of the specified assignment group. If the user is a member of the group, the script returns false, indicating that the item should be available. If the user is not a member of the group, the script returns true, indicating that the item should not be available. You can replace "My Assignment Group" in the script with the name of the assignment group you want to check for.
Regards,
Shravan.
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2023 12:49 AM
Hi @Susanne Bredal ,
Below is the non-tested modified script you can give a try.
checkCondition();
function checkCondition() {
var currentUserID = gs.getUserID(); // Get the ID of the current user
var currentUser = new GlideRecord('sys_user'); // Create a GlideRecord object for the current user
currentUser.get(currentUserID); // Load the current user's record
var groupName = "My Assignment Group"; // Replace this with the name of the assignment group you want to check for
var assignmentGroups = currentUser.getMyGroups(); // Get an array of the current user's assignment groups
for (var i = 0; i < assignmentGroups.length; i++) {
var assignmentGroup = assignmentGroups[i].name.toString(); // Convert the assignment group name to a string
if (assignmentGroup == groupName) {
// If the user is a member of the specified assignment group, return false (meaning the item is available)
return false;
}
}
// If the user is not a member of the specified assignment group, return true (meaning the item is not available)
return true;
}
This script checks if the current user is a member of the specified assignment group. If the user is a member of the group, the script returns false, indicating that the item should be available. If the user is not a member of the group, the script returns true, indicating that the item should not be available. You can replace "My Assignment Group" in the script with the name of the assignment group you want to check for.
Regards,
Shravan.
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2023 03:58 AM
Thank you very very much 😃