Filter names example

Following is an example script of a function.

The function defines an advanced reference qualifier for a user (sys_user) reference variable that filters the available user records to those where Name contains the value of a variable named textmatch on the same item:
function getBlackberryUsers ( ) { var answer  = '' ; var includes  = current. variables. textmatch ; var usr  = new GlideRecord ( 'sys_user' ) ; 
  usr. addQuery ( 'name' , 'CONTAINS' ,includes ) ; 
  usr. query ( ) ; while (usr. next ( ) ) { if (answer. length > 0 ) {
      answer  += ( ',' + usr. sys_id ) ; } else { 
      answer  = '' + usr. sys_id ; } } return 'sys_idIN' + answer ; }