How to log an object in SN?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2023 06:56 AM - edited 08-18-2023 07:02 AM
I have a field that can hold several users, it is of type glide_list. In the XML it shows as a comma-separated string of sysIDs. So I thought I should be able to do a list.split(",") to turn it into an array. But when I finally log "gs.info(typeof list)" it returns "object".
So I try to log the object using the following methods (having first retrieved records using the gliderecord query):
if (gr.next()) {
gs.info(typeof gr.object); --> returns object
gs.info(gr.object); --> returns nothing
gs.info(object.keys(gr.object)); --> returns "org.mozilla.javascript.EcmaError: "object" is not defined.
Caused by error in sys_script_include.[sys_id].etc"
gs.info(object.values(gr.object)); --> returns "org.mozilla.javascript.EcmaError: "object" is not defined.
Caused by error in sys_script_include.[some_other_sys_id].etc"
gs.info(object.entries(gr.object)); --> returns "org.mozilla.javascript.EcmaError: "object" is not defined.
Caused by error in sys_script_include.[some_other_sys_id].etc"
}
For someone with a vanilla JavaScript background, this is both puzzling and frustrating. Is there simply no way to retrieve the data structure of an object in ServiceNow?
Kudos to the best explanation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2023 07:07 AM
@kim-lindgren When I started learning Javascript, I went through below @W3school object page. This will definitely help you to understand object concept.
https://www.w3schools.com/js/js_objects.asp
Below two articles will help how object is being used in ServiceNow
https://www.servicenow.com/community/developer-blog/json-parsing/ba-p/2279166
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2023 07:15 AM - edited 08-18-2023 07:16 AM
That was not a reply to my question and, as I wrote, I have a JavaScript background.
Restating my question:
"For someone with a vanilla JavaScript background, this is both puzzling and frustrating. Is there simply no way to retrieve the data structure of an object in ServiceNow?"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2023 09:15 AM
@kim-lindgren Below two articles will definitely help you.
https://www.servicenow.com/community/developer-blog/json-parsing/ba-p/2279166
https://www.servicenow.com/community/developer-blog/fetch-value-from-json/ba-p/2282127
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2023 01:02 AM
I have looked at the above two articles but I still cannot log the properties of my object. What I get is [object GlideRecord] and there seems no way for me to enter it, including with JSON methods.