- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2022 11:16 PM
we have three list collector varibles
List Collector 1 Variable - users input all members (with and without role)
List Collector 2 (Hidden in the form)- This needs to populate with users from List Collector 1 with no ITIL role
List Collector 3 (Hidden in the form)- This needs to populate with users from List Collector 1 with ITIL role
i used in below script so present it's not checking the users role and if i am selecting any users those coming no access varible so that's worng
script include
var CatUtils = Class.create();
CatUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isLicensed: function(){
var answer = false;
var user = new GlideRecord('sys_user_has_role');
user.addQuery('user' , this.getParameter('sysparm_user'));
user.addQuery('role', '282bf1fac6112285017366cb5f867469'); //ITIL Role
user.query();
if(user.hasNext()){
answer = true;
}
return answer;
},
type: 'CatUtils'
});
Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('getroles');
ga.addParam('sysparm_name','isLicensed');
ga.addParam('sysparm_user',newValue);
ga.getXMLAnswer(response);
function response(answer){
try{
if(answer == 'true'){
addUser(newValue,"user_access");
} else{
addUser(newValue,"no_access");
}
//g_form.setValue('user_list','');
}catch(e){
}
}
function addUser(value,list){
var vals = g_form.getValue(list);
alert('the data'+vals);
if(vals.indexOf(",") > -1 || vals != ''){
vals += "," + value;
} else{
vals = value;
}
g_form.setValue(list,vals);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2022 01:42 AM
Hello Mani,
Please check with below scripts:
Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('getroles');
ga.addParam('sysparm_name','isLicensed');
ga.addParam('sysparm_user',newValue);
ga.getXMLAnswer(parseResponse);
function parseResponse(answer){
try{
var usersData = JSON.parse(answer);
if (usersData["itil_users"]){
var accessUser = usersData["itil_users"];
g_form.setValue("user_access", accessUser.join(","));
}
if (usersData["non_itil_users"]){
var noAccessUser = usersData["non_itil_users"];
g_form.setValue("no_access", noAccessUser.join(","));
}
}catch(e){
}
}
}
Script Include:
var CatUtils = Class.create();
CatUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isLicensed: function(){
var userRoles = {};
var itilRoleUsers = [];
var nonItilRoleUsers = [];
var userGuid = this.getParameter('sysparm_user').split(",");
for (var users in userGuid) {
var userRoleGR = new GlideRecord('sys_user_has_role');
userRoleGR.addQuery('user' , userGuid[users]);
userRoleGR.addQuery('role', '282bf1fac6112285017366cb5f867469'); //ITIL Role
userRoleGR.query();
if(!userRoleGR.hasNext()){
nonItilRoleUsers.push(userGuid[users]);
} else {
userRoleGR.next();
itilRoleUsers.push(userRoleGR.getValue("user"));
}
}
if (nonItilRoleUsers.length)
userRoles["non_itil_users"] = nonItilRoleUsers;
if (itilRoleUsers.length)
userRoles["itil_users"] = itilRoleUsers;
return JSON.stringify(userRoles);
},
type: 'CatUtils'
});
Please mark my respsone as helpful/correct, if it answer your question.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2022 11:44 PM
What exactly is the requirement behind this? I see you are asking several questions on the same topic and it looks to be a very complex solution for something. Maybe there's an easier way (also for the future, when this needs to be maintained). Can you share the use case?
If my answer helped you in any way, please then mark it as helpful. If it resolved the issue, please mark it as correct. This way others will find it in the solved queue and helps them on similar queries.
Mark
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2022 12:39 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2022 01:42 AM
Hello Mani,
Please check with below scripts:
Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('getroles');
ga.addParam('sysparm_name','isLicensed');
ga.addParam('sysparm_user',newValue);
ga.getXMLAnswer(parseResponse);
function parseResponse(answer){
try{
var usersData = JSON.parse(answer);
if (usersData["itil_users"]){
var accessUser = usersData["itil_users"];
g_form.setValue("user_access", accessUser.join(","));
}
if (usersData["non_itil_users"]){
var noAccessUser = usersData["non_itil_users"];
g_form.setValue("no_access", noAccessUser.join(","));
}
}catch(e){
}
}
}
Script Include:
var CatUtils = Class.create();
CatUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isLicensed: function(){
var userRoles = {};
var itilRoleUsers = [];
var nonItilRoleUsers = [];
var userGuid = this.getParameter('sysparm_user').split(",");
for (var users in userGuid) {
var userRoleGR = new GlideRecord('sys_user_has_role');
userRoleGR.addQuery('user' , userGuid[users]);
userRoleGR.addQuery('role', '282bf1fac6112285017366cb5f867469'); //ITIL Role
userRoleGR.query();
if(!userRoleGR.hasNext()){
nonItilRoleUsers.push(userGuid[users]);
} else {
userRoleGR.next();
itilRoleUsers.push(userRoleGR.getValue("user"));
}
}
if (nonItilRoleUsers.length)
userRoles["non_itil_users"] = nonItilRoleUsers;
if (itilRoleUsers.length)
userRoles["itil_users"] = itilRoleUsers;
return JSON.stringify(userRoles);
},
type: 'CatUtils'
});
Please mark my respsone as helpful/correct, if it answer your question.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2022 06:20 AM
Hello
Just wanted to check with you, if the above response answered your question. If yes, then please do close this thread/question by marking the appropriate response as correct.
Thanks