Getting [object Object] undeefined error in Log statement

peri sravani1
Tera Expert

Hi All, Getting below error while printing log statements.

perisravani1_0-1699951451978.png

Below is the code I've written:

let response = r.execute();
        let responseBody = response.getBody();
        let httpStatus = response.getStatusCode();
        let parsedData = JSON.parse(responseBody);

        let opportunities = parsedData.opportunitiesData;
        gs.info("test line 40 "+opportunities);
        totalOpportunities = [...opportunities];
    }

        gs.info("test line 44 "+totalOpportunities);
2 ACCEPTED SOLUTIONS

Prince Arora
Tera Sage
Tera Sage

@peri sravani1 

 

As per the screenshot, this is not an error, you have parsed the JSON thats why you get the data as JSON object

 

Please do it as follows:

 
var opportunities = parsedData.opportunitiesData;
opportunities = JSON.stringify(opportunities);
gs.info(opportunities);
 
If you want to access some object from the JSON tree, you need to parse it and access the data
If you want to check the data in it, you can use JSON.stringify() and it will work for you
 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

View solution in original post

Danish Bhairag2
Tera Sage
Tera Sage

Hi @peri sravani1 ,

 

The Output is in JSON format in order to view it you can stringify it as mentioned by Prince above.

You can write this line instead 

 

gs.info("test line 40 "+JSON.stringify(opportunities));

 

Thanks,

Danish

 

 

View solution in original post

9 REPLIES 9

Prince Arora
Tera Sage
Tera Sage

@peri sravani1 

 

As per the screenshot, this is not an error, you have parsed the JSON thats why you get the data as JSON object

 

Please do it as follows:

 
var opportunities = parsedData.opportunitiesData;
opportunities = JSON.stringify(opportunities);
gs.info(opportunities);
 
If you want to access some object from the JSON tree, you need to parse it and access the data
If you want to check the data in it, you can use JSON.stringify() and it will work for you
 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

Danish Bhairag2
Tera Sage
Tera Sage

Hi @peri sravani1 ,

 

The Output is in JSON format in order to view it you can stringify it as mentioned by Prince above.

You can write this line instead 

 

gs.info("test line 40 "+JSON.stringify(opportunities));

 

Thanks,

Danish

 

 

peri sravani1
Tera Expert

How do I set primary key on to a custom table?
@Danish Bhairag2  @Prince Arora 

@peri sravani1 

 

How you are storing data into the table?

Best practice is to store data into staging table and then transform it into target table using transform map and in transform map you can set the primary key by setting the coalesce field to true.

 

If you are storing the data directly into the table then you need to check before insertion whether that key is already present in the table or not

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.