Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Mark Roethof
Tera Patron

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

 

Hi there,

 

A situation that sounds familiar when working with fields with JSON code: The JSON code hard to read, the code looks unformatted, the structure or errors are hard to spot. So let's open a JSON viewer on the web, copy/paste the code, parse it…

 

While actually, there's a dictionary attribute in ServiceNow which might help you a lot. A hidden gem, already available in ServiceNow for ages: "JSON View". Basically: it will present an icon next to the field label, when you click the icon: the JSON is nicely formatted in a pop-up!

Out-of-the-box

For example, let's have a look at the "Option schema" field on the "Widget" form. This is a JSON field type. As you can see, unformatted.

 

find_real_file.png

Adding the attribute

Within the Dictionary Entry of the field, select the "Attributes" section and click the "New" UI Action.

 

find_real_file.png

 

On the "Dictionary Attribute" new record, simply add:


find_real_file.png

 

Result

After submitting the new Dictionary Attribute, return to the Widget form again. The result will be visible instantly. A small icon next to the field label will be visible.

 

find_real_file.png

 

And now, simply click the icon. A simple pop-up window appears with the JSON code nicely formatted!

 

find_real_file.png

---

And that's it actually. Hope you like this hidden gem. If any questions or remarks, let me know!

 

C

If this content helped you, I would appreciate it if you hit bookmark or mark it as helpful.

 

Interested in more Articles, Blogs, Videos, Podcasts, Share projects I shared/participated in?
- Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

 

Kind regards,


Mark Roethof

ServiceNow Technical Consultant @ Quint Technology
1x ServiceNow Developer MVP

1x ServiceNow Community MVP

---

LinkedIn

Comments
Shakeel Shaik
Giga Sage

Great and very useful.

Thanks for Sharing 🙂

Michael O J
Tera Expert

This is very usefull.

 

Does anyone know if it possible to improve it with color coding. Just like the "view XML" popup.

 

BR

Michael

Shashank_singh9
Tera Expert

Can this functionality be enable for users with itil role, because once they click the JSON button, it shows like this, the user already has access to record.

Shashank_singh9_0-1729677530501.png

 

Raghav Sharma24
Giga Patron

@Mark Roethof This icon is not available on workspace? Does this mean that it is not supported on workspace view?

John Dahl
Kilo Sage

So... IF you already have a JSON field, you can set the attribute and have it formatted. Why can't I add a new JSON field to a table? The option is missing and if I try to add it via a.... creative approach, it's blocked.

Mark Roethof
Tera Patron

@John Dahl Why its not visible, you have to ask ServiceNow 😀

 

How you can make it visible:

MarkRoethof_0-1769065373351.png

 

John Dahl
Kilo Sage

@Mark Roethof I suspect the field type is deprecated. FYI: Now you can just a large string field. They can hold the json content and will accept the json attribute to add the decorator.

Mark Roethof
Tera Patron

@John Dahl If the field is deprecated, why does ServiceNow then creates new fields (even with the Australia release) of this type? So deprecated doesn't sound the correct answer to me.

John Dahl
Kilo Sage

I don't know why they would restrict it, but they do that with List Action fields too...and have for years. You can't select List Action type, but you can force it through a URL parameter.... but the json field type is actively blocked on save of the dictionary record. It's strange. I wonder if there is more security around it because it's used by the NextUI framework for active content?

Version history
Last update:
‎08-03-2024 07:36 AM
Updated by:
Contributors