What is the meaning for below 2 lines ?

Aryan
Tera Contributor

Hi All,

 

I am new in Scripting can anyone explain me what the below 2 lines do?

 

var myObj = new GlideRecord('incident');

myObj.query(); //// -------??????

while(myObj.next()){----??????

7 REPLIES 7

Aryan
Tera Contributor

myObj.query(); 

while(myObj.next())

 

???

@Aryan 

This line of code will check the complete records as there is no condition added and will return you all records which are there in the "incident" table. 
For example: If there are 1000 records, the while loop will return 1000 iterations inside the loop.

 

If my response helps you in any way, please mark my response as helpful or "Accept as Solution" so that your question will help others as well

Thank you

The best way to check your code would be:

Run the same three line of code in the "Scripts - Background" module in your Servicenow instance.

 

var myObj = new GlideRecord('incident');

myObj.query(); //// -------??????

while(myObj.next()){
gs.info("Incident Row Count: "+myObj.number);
}

 

 

@Aryan 

 

Let me know if you need any more help this and kindly close the thread.

 

If my above response helps you in any way, please mark my response as helpful or "Accept as Solution" so that your question will help others as well

Thank you