logo

NJP

ServiceNow Things to Know 48: get() function

Import · Dec 23, 2023 · article

You may know that get() function can accept two arguments. When you pass two arguments, the first becomes the column for searching and the second is the value. But you should also know that get() can return multiple records based on the condition passed. So do not write your script under the assumption that get() will return only one record.

Script:

var incident = new GlideRecord('incident');

if (incident.get('caller_id', gs.getUserID())) { //This returns more than one record

gs.print(incident.number);

incident.next(); //You can iterate to next record like a normal gliderecord query

gs.print(incident.number);

}

If my content helped you in anyway, please mark this content as BOOKMARK, SUBSCRIBE & HELPFUL

Best Regards,

Prashant Kumar (LearnIT)

YouTube Channel LearnIT: https://www.youtube.com/@learnitwithprashant

Blog LearnIT: https://medium.com/@LearnITbyPrashant

Prashant Kumar LinkedIn: https://www.linkedin.com/in/learnitbyprashant/

ServiceNow Community Prashant Kumar - https://www.servicenow.com/community/user/viewprofilepage/user-id/19635

View original source

https://www.servicenow.com/community/developer-blog/servicenow-things-to-know-48-get-function/ba-p/2772033