What's the difference b/w next() and hasNext()?

jamesgo
Giga Contributor

if the query has only one match, will hasNext() return true?

11 REPLIES 11

kumaril1
Giga Expert

hasNext() : hasNext() method returns true if iterator have more elements.


next() : next() method returns the next element and also moves to the next element.


may I have any good example related to next() and hasNext()

You can check my reply above or take a look at the GlideRecord documentation for examples: next() 

Ravindra Swami
Tera Contributor

I am a learner on service now and i want to set a regex on name field. please help me in this case

condition is that you should not enter any other character rather than a-z, A-Z and space only

Hey Ravindra, 
[a-zA-Z\s] : use this in On-change client script for the Name field.

Also, its not the best practice to limit the name field for below reasons:
1. its a read-only by OOB.
2. In future you might store integration users thier name may include "numbers".
3. Name is auto-populated by First Name & Last Name, you will/have to disturb this logic. (Highly Not Recommended).

 

NOTE: If my knowledge helped you to learn / understand the waters. Please leave a HELPFUL. thanks !