add one query also, if passed user is the member of passed group or the member of health…
- User
add one query also, if passed user is the member of passed group or the member of health group var gr = new GlideRecord('sys_user_grmember'); gr.addQuery('user', userSysId); gr.addQuery('group', groupSysId); gr.query(); if (gr.next()){
- Assistant
You want to check if a user is a member of either a specific group (passed in
groupSysId) or the "health" group.Assuming you have the
groupSysIdto check against, and you also want to check membership in a "health" group.Step 1: You need to get the Sys ID of the "health" group (assuming you know its name or some identifier).
Step 2: Then, you add a query that matches user membership either in the given group OR in the health group.
Here's how you can do it:
var healthGroupSysId = ''; // Initialize or fetch it as shown below // Option 1: If you know the name of the health group, get its sys_id: var grHealthGroup = new GlideRecord('sys_user_group'); grHealthGroup.addQuery('name', 'Health'); // or the actual group name grHealthGroup.query(); if (grHealthGroup.next()) { healthGroupSysId = grHealthGroup.sys_id.toString(); } // Now, query membership for either the passed group or the health group var gr = new GlideRecord('sys_user_grmember'); gr.addQuery('user', userSysId); var groupQuery = gr.addQuery('group', groupSysId); groupQuery.addOrCondition('group', healthGroupSysId); gr.query(); if (gr.next()) { // User is member of the passed group OR health group } - User
i have the sysid also
- Assistant
Great! Since you already have the sys_id of the health group, you can simplify your code like this:
var healthGroupSysId = '<health_group_sysid>'; // Replace with actual sys_id var gr = new GlideRecord('sys_user_grmember'); gr.addQuery('user', userSysId); var groupQuery = gr.addQuery('group', groupSysId); groupQuery.addOrCondition('group', healthGroupSysId); gr.query(); if (gr.next()) { // User is a member of the passed group OR the health group }Just replace
<health_group_sysid>with your actual health group sys_id, and this will work as expected.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.