why we cant return object through script include ajax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
hey when i share object/array from ajax script include at that time it cant receive whole object/array at client side , to resolve that i have to first convert object/array in string using JSON.stringify() method and at client side i need to parse the receiving string , why we cant send object directly without converting into string
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @adityahubli
When you use GlideAjax (Script Include ↔ Client Script), you’re not just calling a JavaScript function directly — you’re actually making an HTTP request from the browser to the server and back.
HTTP (and GlideAjax built on top of it) only knows how to send/receive data as text (string). It doesn’t understand native JavaScript objects or arrays
That’s why:
On the server side, even if you build an object/array, you must convert it into a string (JSON.stringify) so it can travel over the network as plain text.
On the client side, you take that string and turn it back into a usable JavaScript object (JSON.parse).
If ServiceNow allowed sending native objects directly, the browser and server would have to share the same memory space and JavaScript runtime — which isn’t possible in a request/response model. The only universal, lightweight way to transfer structured data is via a serialized string format (like JSON or XML).
👉 So the short answer: We send only strings because GlideAjax works over HTTP, and HTTP transfers data as text. Objects/arrays must first be serialized (stringified) to be transmitted.
If my answer helped you, please consider marking it as ✅ Correct and giving it a 👍 Helpful — it might help other members in the community too!
Thanks,
Astik T ✨
ServiceNow Community Rising Star 2025 🌟
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @adityahubli ,
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Thanks,
Astik T ✨
ServiceNow Community Rising Star 2025 🌟
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Objects/arrays must be stringified (using JSON.stringify()) before sending from ServiceNow AJAX Script Include, because GlideAjax transmits only text, not native objects. On the client, use JSON.parse() to restore them.
This is required due to HTTP/AJAX using only text-based data formats, and GlideAjax’s string-only returns.
good explanation here
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