checking if a record exists using get()

ServiceNow Use6
Tera Guru

Hello,

I wrote a script where I can check if a record exists with the following condition and it is not able to find.

var methods = new GlideRecord("incident");
var returnValue = methods.get("caller_id", "Bud Richman");
gs.addInfoMessage("the record that is to be returned is available " + returnValue);

It is returning false even though there is  record with the scenario

Regards

Suman P.

1 ACCEPTED SOLUTION

Mark Roethof
Tera Patron
Tera Patron

Hi there,

methods.get("caller_id", "Bud Richman");

caller_id is a reference, so sys_id. You are searching on a string though. That won't work.

So either search on the sys_id, or use caller_id.name

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

5 REPLIES 5

Mark Roethof
Tera Patron
Tera Patron

Hi there,

methods.get("caller_id", "Bud Richman");

caller_id is a reference, so sys_id. You are searching on a string though. That won't work.

So either search on the sys_id, or use caller_id.name

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Mark Roethof
Tera Patron
Tera Patron

And just to add, even if this would work, what if "Bud Richman" is a Caller in multiple incidents? You are only returning 1 incident with this script. Or is this just to validate, if Bud Richman has any incidents where Bud is registered as caller?

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hi Mark,

Nothing specific, I am just making sure GlideRecord works for me for learning.

Regards

Suman P.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can check points mentioned by Mark around sys_id for caller

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader