- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2024 07:20 AM
Hii All i have two fields one field name is demo1 which is refrence type refrence is of group table , second field name is company which is list type and refrence give it of user table , now my requirement is that when i select any group in demo field how many user are in that group should populate in company field i make script include my script is below getGroupMembers: function(groupId) { var groupMembers = []; var gr = new GlideRecord('sys_user_grmember'); gr.addQuery('group', groupId); gr.query(); while (gr.next()) { groupMembers.push(gr.user.toString()); } gs.info('Group ID: ' + groupId); gs.info('Group Members: ' + groupMembers.join(', ')); return groupMembers; }, type: 'GroupMemberScriptInclude' }; now this script include need to call from refrence qualifier , here i do not know on which field refrence qualifier use to achive this i tried but no luck thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 02:49 AM
Hello @dheeru_1994 ,
You can write a onchnage client script on group field and depending on that you can set the value of list collector field by using simililar script include.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2024 07:45 AM - edited 01-18-2024 07:50 AM
Hello @dheeru_1994 ,
you need to call script include in company field. use the below format for calling the script include.
See the commutiy link as well: https://www.servicenow.com/community/developer-forum/call-script-include-from-reference-qualifier/m-...
Kindly mark the answer ✔️Correct or Helpful ✔️If it addresses your concern.
Regards,
Siddhesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2024 08:00 AM - edited 01-18-2024 08:04 AM
Hi @dheeru_1994 ,
You need to call ur script include from company field.
Write this code in the Reference qualifier of the company field.
javascript : new GroupMemberScriptInclude().getGroupMembers(current.demo1);
Note : after javascript just add : remove wht is written above.
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2024 08:38 AM
javascript: new GroupMemberScriptInclude().getGroupMembers(current.u_company.sys_id)
in my list type field is demo1
and my script include is
by doing this logs are printing but on list type field group member are not printing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 12:43 AM - edited 01-19-2024 01:06 AM
Hello @dheeru_1994 ,
I made some changes in your script and it is working perfectly. Please try and let me know.
Script Include:
var GroupMemberScriptInclude = Class.create();
GroupMemberScriptInclude.prototype = {
initialize: function() {
},
getGroupMembers: function(current) {
var groupMembers = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', current.u_select_group); // Use your field Name
gr.query();
while(gr.next()) {
groupMembers.push(gr.user.toString());
}
return 'sys_idIN'+groupMembers;
},
type: 'GroupMemberScriptInclude'
};
Reference qualifier:
Kindly mark the answer ✔️Correct or Helpful ✔️If it addresses your concern.
Regards,
Siddhesh