JSON saved data is showing up empty

ServNowDev
Tera Guru

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

 

Screenshot 2023-10-05 at 1.10.25 AM.png

 

7 REPLIES 7

Vishal Birajdar
Giga Sage

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);

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

updated the code to have semicolons on the jsonData lines and same issue still blank values

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);

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

does not seem to be storing source data any reason why not?