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

Sandeep Rajput
Tera Patron
Tera Patron

@Aryan On the line 1, myObj.query(); instructs the compiler to query the incident table and find the records which are matching with the query. Since no query conditions are defined here, all the records from incident table will be fetched.

 

On line 2 while(myObj.next()) a while loop it using to fetch all the incident records, this loop runs till the next method returns true.

 

For more information on query please refer to https://developer.servicenow.com/dev.do#!/reference/api/vancouver/server/no-namespace/c_GlideAggrega... and for more information on next please refer to https://developer.servicenow.com/dev.do#!/reference/api/vancouver/server/no-namespace/c_GlideRecordS...

 

Hope this helps.

Parth_Poriya
Tera Expert

Hii

 

1st line =   Means it execute the query which u have given in addQuery() method.

2nd line = Means whatever result is given it will iterate and search whether thier is next record or not

Samiksha Gunjat
Kilo Guru

Hi @Aryan,

1)myObj.query() :- initiates a query on the GlideRecord object myObj, retrieving all records from the specified table.

2)while(myObj.next()):-

  • while: This is a control flow statement that repeats a block of code as long as the specified condition is true.
  • myObj.next(): This method is used to iterate through the records returned by the query. It moves the GlideRecord pointer to the next record in the result set. If there are no more records, it returns false; otherwise, it returns true.

        Regards,
        Samiksha Gunjate