- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2020 12:47 AM
Hi, I am trying to restrict users submitting request based on ownership. Only the users part of groups owning the server should be able to submit. here is the code i have written which is not working. this is an onchange script
var server = g_form.getReference('server',myfunc)
var user_ID = g_user.userID.split;
var servergroup = server.u_servergroups.split(,);
function myfunc(server){
var result = false;
if (server){
for(var i=0; i<servergroups.length; i++){
if(user_ID.isMemberof(servergroups[i])){
result = true;
alert(' is user part of server groups: ' + result);
}
}
}
}
Solved! Go to Solution.
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2020 10:20 AM
Hi Harish,
Are you saying user will select some server and in server there is a list type of field which refers group table and if user is member of any of those group then show alert
you need to use GlideAjax and Script include for this
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var server = g_form.getReference('server').u_servergroups;
var ga = new GlideAjax('u_userInfoAjax');
ga.addParam('sysparm_name', "getInfo");
ga.addParam('sysparm_server ', server );
ga.getXMLAnswer(function(answer){
if(answer.toString() == 'true')
alert('is user part of server groups:');
});
}
Script Include:
var u_userInfoAjax = Class.create();
u_userInfoAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getInfo: function(){
var groups = this.getParameter('sysparm_server');
var groupsArray = groups.toString().split(',');
var flag = false;
for(var i=0;i<groupsArray.length;i++){
if(gs.getUser().isMemberOf(groupsArray[i]))
flag = true;
}
return flag;
},
type: 'u_userInfoAjax'
});
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2020 10:20 AM
Hi Harish,
Are you saying user will select some server and in server there is a list type of field which refers group table and if user is member of any of those group then show alert
you need to use GlideAjax and Script include for this
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var server = g_form.getReference('server').u_servergroups;
var ga = new GlideAjax('u_userInfoAjax');
ga.addParam('sysparm_name', "getInfo");
ga.addParam('sysparm_server ', server );
ga.getXMLAnswer(function(answer){
if(answer.toString() == 'true')
alert('is user part of server groups:');
});
}
Script Include:
var u_userInfoAjax = Class.create();
u_userInfoAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getInfo: function(){
var groups = this.getParameter('sysparm_server');
var groupsArray = groups.toString().split(',');
var flag = false;
for(var i=0;i<groupsArray.length;i++){
if(gs.getUser().isMemberOf(groupsArray[i]))
flag = true;
}
return flag;
},
type: 'u_userInfoAjax'
});
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2020 05:19 AM
var server = g_form.getReference('server').u_servergroups;
above assignement is returning the sys_id's of the groups not the group name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2020 05:37 AM
Hi Harish,
that could be because the u_servergroups is a reference or glide list field in the table being referred by server variable
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2020 06:00 AM
So we could still compare sys_id's of group and with sys_id of user in isMemberOf function?