Need to fetch list of users

kulshreshtha
Giga Contributor

I have synced azure ad to servicenow. Now i need to get the list of users present in servicenow. How can this be done using client script?

1 ACCEPTED SOLUTION

yes in servicenow when you create a variable there are different variable types. One is a String type which you are probably using. You can create a reference type and that should do what you are explaining above ^.



find_real_file.png



This is what it will look like on the form



find_real_file.png



if they enter a name that is not in the user table this happens...



find_real_file.png



I believe this is what you are looking for. No need to customize this


View solution in original post

16 REPLIES 16

kulshreshtha
Giga Contributor

function onChange(control, oldValue, newValue, isLoading) {


  if (isLoading || newValue == '') {


  return;


  }


  if(!(/^[a-zA-Z\s]*$/g.test(newValue))==false){


  alert(newValue);


  var test="vig";


  var decide="fsf";


  var gr = new GlideRecord('sys_user');


  gr.query("user_name");


  while(gr.next())   {


  var dbname=gr.name;




  if(dbname==newValue){


         


          decide="worked";


          break;


         


      }}


    if(decide!="worked"){


                g_form.setValue('username','');


                alert("User not present in DB");


          }


 



 


}


  else{


  g_form.setValue('username','');


  alert("Only letters are allowed");


  }


}




Thsi has worked for me.. Thanks all for the reply


Mark ANSWER AS CORRECT For closing this thread.


I am not sure what your form is for or what the logic is exactly for. but if you created a mandatory reference field to the user table. if the user submitting the form it already has the logic in place to look up and see what is in the database and too see if they spelled someone's name correctly and also reference that user record.


Hi Nathan



I have created input text box which takes a username,(should not accept any other characters/numbers) in azure vm template.Here when user inputs a name it should be validated with the names present in user table.So I am checking username entered against the name coming from user table.


yes in servicenow when you create a variable there are different variable types. One is a String type which you are probably using. You can create a reference type and that should do what you are explaining above ^.



find_real_file.png



This is what it will look like on the form



find_real_file.png



if they enter a name that is not in the user table this happens...



find_real_file.png



I believe this is what you are looking for. No need to customize this