The CreatorCon Call for Content is officially open! Get started here.

Available for script - on assignment group

Susanne Bredal
Tera Contributor

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 🙂

1 ACCEPTED SOLUTION

Sai Shravan
Mega Sage

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.

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

View solution in original post

2 REPLIES 2

Sai Shravan
Mega Sage

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.

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

Thank you very very much 😃