Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to log an object in SN?

kim-lindgren
Kilo Sage

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.

4 REPLIES 4

SANDEEP28
Mega Sage

@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

 

https://www.servicenow.com/community/developer-blog/fetch-value-from-json/ba-p/2282127https://www.se...

 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !! 

 

 

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?"

kim-lindgren
Kilo Sage

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.