- 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
04-24-2020 06:08 AM
Hi Harish,
if those are group sys ids or group name isMemberOf() works with both
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-05-2020 10:00 AM
Hi Harish,
Any update on this?
Can you mark my answer as ✅ correct, 👍 helpful if you were able to achieve the requirement. This enables other members to learn from this thread.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader