- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 06:09 PM
Hi All,
I have a requirement to filter Assignment group but ONLY if the type is Normal. I know how to use the simple and advanced. I have not done this using Dynamic which I think is what I need (please let me know if this is not correct).
So I want to return only 4 groups if the type is Normal. If it's any other type, I do not want to filter the groups. Is there a quick way to say
if (type == "normal"){
var mygrps= [];
var gr= new GlideRecord('sys_user_group');
gr.addQuery('cm', true);
gr.query();
while(gr.next()) {
mygrps.push(gr.sys_id);
}
return mygrps;
}else{
// do nothing? I would like to see all the groups if it's not normal type
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 07:54 PM
Hi @MWright1 ,
Just create one script include and pass the value of assignment group type through reference qualifier.
- Assignment group reference qualifier:
- javascript:new TestingReference.().getInfo(current.assignment_group.type);//on the table side if you are on catalog sidethen use: javascript:new TestingReference.().getInfo(current.variables.assignment_group_variable_name.type);
- Use below script inlcude
- var TestingReference = Class.create();TestingReference.prototype = Object.extendsObject(AbstractAjaxProcessor, {getInfo: function(type) {var list=[];if(type=='2e763549d7111100828320300e61038d')//pass the sys_id of group type normal{var gr=new GlideRecord('sys_user_group');gr.addQuery('type',type);gr.query();while(gr.next()){list.push(gr.getValue('sys_id'));}return 'sys_idIN'+list;}else// it will return all the list of group including normal type as well{var gr=new GlideRecord('sys_user_group');gr.addQuery('active',true);gr.query();while(gr.next()){list.push(gr.getValue('sys_id'));}return 'sys_idIN'+list;}},type: 'TestingReference'});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 11:16 AM
Hi @Murthy Ch
Yeah you are right I know if condition is not true then obviously it will return all the available records but for code readability and for clear understanding of flow i have mentioned the else part.
Thanks
Seraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 08:06 PM
Hi @MWright1 ,
Follow the Below Steps:
Step 1 - Write a script include with the appropriate code:
if (type == "normal"){
var mygrps= 'sys_idIN';
var gr= new GlideRecord('sys_user_group');
gr.addQuery('cm', true);
gr.query();
while(gr.next()) {
mygrps += gr.sys_id + ',';
}
mygrps = mygrps.slice(0, -1); // Remove the last comma
return mygrps;
}
Step 2 - Navigate All->Dynamic filter options->create new
Here choose Name, table, and in the script you need [ new Script_inc_name().Function(current.variables.type)
Step 3 - Now go to the Field where you want to apply this filter, there
Select type as Dynamic, then choose the appropriate Dynamic filter option which you created in step 2.
Step 4- Save the changes.