JSON saved data is showing up empty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 10:11 PM
I have a transform script that takes the source data and puts into a json and then put that json info into a Script Field on the target table. Here is the code below but the field on the target table keeps displaying the data with empty values.
(function runTransformScript(source, map, log, target) {
// Add your code here
var jsonData = {
destination: source.u_destination_country,
departure_date: source.u_departure_date,
return_date: source.u_return_date,
};
var jsonString = JSON.stringify(jsonData);
target.actual_data = jsonString;
})(source, map, log, target);
I have a client script as well but its not showing any help to display the data, here is what the field looks like below empty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 10:18 PM
Hi @ServNowDev
Can you try like below :
(function runTransformScript(source, map, log, target) {
// Add your code here
var jsonData = {
destination: '',
departure_date: '',
return_date: '',
};
jsonData.destination = source.u_destination_country,
jsonData.departure_date = source.u_departure_date,
jsonData.return_date =source.u_return_date,
var jsonString = JSON.stringify(jsonData);
target.actual_data = jsonString;
})(source, map, log, target);
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 10:35 PM
updated the code to have semicolons on the jsonData lines and same issue still blank values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 10:46 PM
Can you put some logs & check if you are getting 'source' data.
(function runTransformScript(source, map, log, target) {
/*Put some logs here*/
gs.log("Source Destination =" + source.u_destination_country);
gs.log("Source Dept date =" + source.u_departure_date);
gs.log("Source return date =" + source.u_return_date);
// Add your code here
var jsonData = {
destination: '',
departure_date: '',
return_date: '',
};
jsonData.destination = source.u_destination_country,
jsonData.departure_date = source.u_departure_date,
jsonData.return_date =source.u_return_date,
var jsonString = JSON.stringify(jsonData);
target.actual_data = jsonString;
})(source, map, log, target);
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 11:00 PM
does not seem to be storing source data any reason why not?