- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago - last edited 4 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
4 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
4 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
4 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
4 weeks ago
try this and it should work if accountId is sysId of that account record
var accountRec = new GlideRecord("customer_account");
accountRec.addQuery('sys_id', accountId);
accountRec.query();
if (accountRec.next()) {
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
}
If my response helped please mark it correct and close the thread 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
4 weeks ago - last edited 4 weeks ago
Hi Ankur,
Thank you so much for your reply.
I just tried it. Still return "", And the query can get return result, also there's value stores in "u_service_location" field
var accountRec = new GlideRecord("customer_account");
//accountRec.get(accountId);
accountRec.addQuery("sys_id",accountId);
accountRec.query();
var serLoc = "";
if(accountRec.next()){
serLoc = accountRec.u_service_location;
}
gs.info("-====serLoc==="+serLoc);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Thank you for all of your replies.
When I use blow code, it worked.
Thank you for all
if (accountRec.next()){
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 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