GlideRecord - is NULL or does not contain value

kristenankeny
Tera Guru

I have a situation where I need to query our groups via GlideRecord and I need to check if "type" is either null or does not contain one of the types. I've tried a few different ways of doing this, but either don't return the null types, return all groups, or don't get any groups. This is the current script (returns nothing because of the addnullquery):

//Check group membership

  var m = new GlideRecord('sys_user_grmember');

  m.addQuery('user',current.sys_id);

  m.query();

  var groupList = [];

  while(m.next()){

  groupList.push(m.group + '');

  }

  groupList = new ArrayUtil().unique(groupList);

  var gm = new GlideRecord('sys_user_group');

  gm.addQuery('sys_id','IN',groupList);

  gm.addQuery('type','DOES NOT CONTAIN','64d411974f082240709af7e18110c76c');

  var gm2 = gm.addNullQuery('type');

  gm2.orderBy('name');

  gm2.query();

  while(gm2.next()){

  gs.info('2MonitorInactiveUsers Group' + gm2.name + 'Member');

  addToDescription('Group',gm2.name,'Member');

  }

1 ACCEPTED SOLUTION

Kalaiarasan Pus
Giga Sage

Instead this section,



  gm.addQuery('sys_id','IN',groupList);


  gm.addQuery('type','DOES NOT CONTAIN','64d411974f082240709af7e18110c76c');


  var gm2 = gm.addNullQuery('type');



Form the query on UI by changing the filter condition. Right click on the filter and copy query.


Later use the copied query in a addEncodedQuery.


View solution in original post

3 REPLIES 3

Kalaiarasan Pus
Giga Sage

Instead this section,



  gm.addQuery('sys_id','IN',groupList);


  gm.addQuery('type','DOES NOT CONTAIN','64d411974f082240709af7e18110c76c');


  var gm2 = gm.addNullQuery('type');



Form the query on UI by changing the filter condition. Right click on the filter and copy query.


Later use the copied query in a addEncodedQuery.


Hi Kristen,

 

 

 

To supplement what Kalai said - If you want a walk-thru video demo

 

 

 

Video: Scripting Complex Queries Quickly

 

kristenankeny
Tera Guru

Thanks Kalai and Chuck! That helped and it's working now.