How to restrict record producer for user specific country

rmaroti
Tera Contributor

Hi All,

 

Requirement: I have one record producer which I want give the access for only those user which country should be Argentina ,Brazil, Colombia, Mexico in their profile i.e location.country so how we can add in available for to restrict the access for other country except above four country.

1 ACCEPTED SOLUTION

Hi @rmaroti I have updated the code as below

var answer;
var userSysId = gs.getUserID(); // get current user sys_id
var userGr = new GlideRecord('sys_user');
if (userGr.get(userSysId)) {
var userCountry = userGr.location.country.toString(); // get user's country
if (userCountry == 'Argentina' || userCountry == 'Brazil' || userCountry == 'Colombia' || userCountry == 'Mexico') {
answer = true;
else {
answer = false;
}
}

Let me know if this works

Regards
Harish

View solution in original post

13 REPLIES 13

Sohithanjan G
Kilo Sage
Kilo Sage

Hi @rmaroti 

 

You can use the below script in the advanced part script in the Available for User Criteria. 

 

1. Create a user criteria & add the condition in it

 

checkCondition();

function checkCondition() {
    var user = new GlideRecord('sys_user');
    user.get(gs.getUserID());

    // Define the allowed countries
    var allowedCountries = ["Argentina", "Brazil", "Colombia", "Mexico"];

    // Check if the user's country is in the allowed list
    if (user.isValidRecord() && allowedCountries.includes(user.location.country)) {
        // User's country is allowed, so return true to grant access
        return true;
    } else {
        // User's country is not allowed, so return false to deny access
        return false;
    }
}

 

 

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

hi @Sohithanjan G  - when I use the above code allowed country users also not accessible the record producer.

 

plz find attached screenshot.

Hi @rmaroti , 

 

Add toString()

 

updated code. its working for me well. 

checkCondition();

function checkCondition() {
    var user = new GlideRecord('sys_user');
    user.get(gs.getUserID());

    // Define the allowed countries
    var allowedCountries = ["Argentina", "Brazil", "Colombia", "Mexico"];

    // Check if the user's country is in the allowed list
    if (user.isValidRecord() && allowedCountries.includes(user.location.country.toString())) {
        // User's country is allowed, so return true to grant access
        return true;
    } else {
        // User's country is not allowed, so return false to deny access
        return false;
    }
}

 

🙂

 

 

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

Harish KM
Kilo Patron
Kilo Patron

Hi @rmaroti you would need to create a User Criteria and check if user is part of the country specified and return true.Add this user criteria to the record producer related list under Available For

Script:

var userSysId = gs.getUserID(); // get current user sys_id
var userGr = new GlideRecord('sys_user');
if (userGr.get(userSysId)) {
var userCountry = userGr.location.country; // get user's country
if (userCountry == 'Argentina' || userCountry == 'Brazil' || userCountry == 'Colombia' || userCountry == 'Mexico') {
return true;
} else {
return false;
}
}

Regards
Harish