Writing Complex Object into Environment Variables or Global Variables

Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.

Here’s an outline with best practices for making your inquiry.

My question:
How do I add a complex Object into Environment Variables or Global Variables.
var settlementValues = new Object();

   var requestData = pm.request.body.raw;

   var requestjson=JSON.parse(requestData);

     

    settlementValues.TransactionCode=requestjson.ProcessingCode.TransactionCode;

    settlementValues.TransactionAmount= requestjson.TransactionAmount.Amount;

    settlementValues.ReferenceNumber=requestjson.RetrievalReferenceNumber;

    settlementValues.BanknetReferenceNumber=requestjson.NormalizedData.MastercardData.BanknetReferenceNumber;

    console.log(settlementValues);

    pm.environment.set("SETTLEMENTOBJECT",settlementValues);

Details (like screenshots):

When I use above piece of code I see the value as [object, Object] instead of complex object .

How I found the problem:

I’ve already tried:

Hey @makaleem1986 :wave:

You need to convert your JS object to string before storing it to the environment,
You can try something like this:


pm.environment.set("SETTLEMENTOBJECT",JSON.stringify(settlementValues));

Good luck!