How to restrict one variable to a particular two groups

Community Alums
Not applicable

Hi,

I tried to write the code for this but I am unable to integrate the variable "Add to URL" to the code. I am just checking the logged in user is a member of the groups or not. I am unable to know how the variable is available to these groups only. Kindly help.

 

onload.PNG

 

function onLoad() {

    var user1 = g_user.userID;
    if ((user1.isMemberOf("WEB DLP") || (user1.isMemberOf("CASB")))) {
        return true;
    } else {
        return false;
    }
	}

 

Regards

Suman P.

1 REPLY 1

Harish Bainsla
Kilo Patron
Kilo Patron

// Assuming 'current' is the current GlideUser (logged-in user) record in ServiceNow
var user = gs.getUser();

// Get the value of the 'Add to URL' variable from the URL parameters
var addToUrl = gs.getParameter('Add to URL'); // Make sure you URL-decode if needed

// Split the 'Add to URL' value into an array of group names
var groupNames = addToUrl.split(',');

// Check if the user is a member of any of the specified groups
var isMemberOfAnyGroup = false;
for (var i = 0; i < groupNames.length; i++) {
if (user.isMemberOf(groupNames[i])) {
isMemberOfAnyGroup = true;
break; // Exit the loop if a match is found
}
}

if (isMemberOfAnyGroup) {
// User is a member of at least one group
gs.log("User is a member of at least one group.");
} else {
// User is not a member of any group
gs.log("User is not a member of any group.");
}