- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 05:02 AM
Hi,
I am trying to pass a variable into a json but unfortunatly the output is empty.
If I take this exemple
// Creating the object to later be JSON encoded var json = {"opened_by":"62826bf03710200044e0bfc8bcbe5df1","requested_for": newReferent,"department":"221f3db5c6112284009f4becd3039cc9"};
the line requested_for of the object return empty {}
But when I log it just before it return the sys id of the user.
Can someone know how to pass variable to json ?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 05:15 AM
Hi Elena,
I am going to make some assumptions since the code for getting newReferent isn't provided. But when you are assigning newReferent your post reads like it should be a sys_id. I'm assuming you're getting that from a GlideRecord or maybe even a value from a field.
When assigning to newReferent I would make it a string. Or at least when assigning it to your literal object, assign as a string.
i.e.
var json = {
"opened_by":"62826bf03710200044e0bfc8bcbe5df1",
"requested_for": newReferent.toString(),
"department":"221f3db5c6112284009f4becd3039cc9"
};
Depending upon how and where you are assigning newReferent the type is getting skewed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 05:06 AM
hello
usually we pass elements into json like below
var obj ={};
obj.name ="mohith";
obj.company="globant";
and if you try to print obj its {"name":"mohith",""company":"globant"}
But in your case paste the script how you are trying to build the json then we will be able to guide you
Please mark my answer correct if it helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 05:15 AM
Hi Elena,
I am going to make some assumptions since the code for getting newReferent isn't provided. But when you are assigning newReferent your post reads like it should be a sys_id. I'm assuming you're getting that from a GlideRecord or maybe even a value from a field.
When assigning to newReferent I would make it a string. Or at least when assigning it to your literal object, assign as a string.
i.e.
var json = {
"opened_by":"62826bf03710200044e0bfc8bcbe5df1",
"requested_for": newReferent.toString(),
"department":"221f3db5c6112284009f4becd3039cc9"
};
Depending upon how and where you are assigning newReferent the type is getting skewed.