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

it is showing error like' return true should be outside of the function"

Hi @rmaroti updated the code

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; // get user's country
if (userCountry == 'Argentina' || userCountry == 'Brazil' || userCountry == 'Colombia' || userCountry == 'Mexico') {
answer = true;
} else {
answer = false;
}
}
Regards
Harish

Hi @rmaroti did you test my code?

Regards
Harish

Hi @Harish KM  - even i tried your code still same thing happened logged in user who has country from one of them from condition still it is not accessible.

 

Hi @rmaroti can you share the field name from user table how country is looked up and also country values? I think the name of the country is not matching in the script.

var userCountry = userGr.location.country; // get user's country

gs.info("country is=="+userCountry);

Can you print the log here and provide me the values

Regards
Harish