- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi experts,
In table [customer_account], we created a customized field u_service_location with type of list and reference to another table [cmn_location],
but in service side script when I use the following list, I always get "" or null for that field.
I'm sure there has value in that field. How can I get value from that field?
var accountRec = new GlideRecord("customer_account");
accountRec.get(accountId);
var aa= accountRec.u_service_location;// return ""
var bb= String(accountRec.u_service_location);// return ""
var cc= JSON.stringify(accountRec.u_service_location);// return {}
var dd= accountRec.u_service_location.toString();// return ""
var ee= accountRec.getValue("u_service_location");// return null
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @SystemsGo ,
try this -- as this is an async call you need to check next().
var accountRec = new GlideRecord("customer_account");
accountRec.get(accountId);
if (accountRec.next()){
var ee= accountRec.getValue("u_service_location");
}
If you found this response helpful, please mark it as the accepted solution and give it a ‘Helpful’ rating. Your feedback supports better answers and benefits the entire community.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @SystemsGo
I don't know what "accountId" is, however when using the get() method of GlideRecord you ALWAYS have to check if there was a result. Otherwise you would work on an empty object (which could be the case for you).
var accountRec = new GlideRecord("customer_account");
if (accountRec.get(accountId)) {
var aa= accountRec.u_service_location;// return ""
var bb= String(accountRec.u_service_location);// return ""
var cc= JSON.stringify(accountRec.u_service_location);// return {}
var dd= accountRec.u_service_location.toString();// return ""
var ee= accountRec.getValue("u_service_location");// return null
}
else {
gs.error('No record found!');
}
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I believe I shared similar code.
If my response helped please mark it correct as well so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @SystemsGo ,
try this -- as this is an async call you need to check next().
var accountRec = new GlideRecord("customer_account");
accountRec.get(accountId);
if (accountRec.next()){
var ee= accountRec.getValue("u_service_location");
}
If you found this response helpful, please mark it as the accepted solution and give it a ‘Helpful’ rating. Your feedback supports better answers and benefits the entire community.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
This is not an async call!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I've just tried, it still return "";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @SystemsGo
I don't know what "accountId" is, however when using the get() method of GlideRecord you ALWAYS have to check if there was a result. Otherwise you would work on an empty object (which could be the case for you).
var accountRec = new GlideRecord("customer_account");
if (accountRec.get(accountId)) {
var aa= accountRec.u_service_location;// return ""
var bb= String(accountRec.u_service_location);// return ""
var cc= JSON.stringify(accountRec.u_service_location);// return {}
var dd= accountRec.u_service_location.toString();// return ""
var ee= accountRec.getValue("u_service_location");// return null
}
else {
gs.error('No record found!');
}
Maik