[object Object] return from JSON array

Tyler Michals
Kilo Guru

Below is a piece of the JSON response from a rest message we sent to a third party. We are having issues returning the info in the "orders" array. We are able to call the href, total, next, limit, and offset objects, but cannot return any objects in the array. All we get is [object Object]. Here is a snippet of the script we are using. Dot walking the objects in service-now does not seem to work. Please help! 🙂

var response = smt.execute();
var responseBody = response.getBody();
var statur = response.getStatusCode();
gs.info(responseBody);

var obj = JSON.parse(responseBody);
var orders = obj.orders;
gs.info(orders.length);

for ( var i=0; i < orders.length; i++){
gs.info(orders[i]);
}

 

{
"href": "https://ecommerce/orders",
"total": 1619,
"next": "https://ecommerce/orders",
"limit": 50,
"offset": 0,
"orders": [
{
"orderId": "192614546834698h4698h4641534",
"legacyOrderId": "192614546h946794569409699009",
"creationDate": "2018-08-15T16:07:59.000Z",
"lastModifiedDate": "2018-08-15T16:11:05.000Z",
"orderFulfillmentStatus": "NOT_STARTED",
"orderPaymentStatus": "PAID",
"sellerId": "seller123",
"buyer": {
"username": "buyer123"
},
"pricingSummary": {
"priceSubtotal": {
"value": "104.95",
"currency": "USD"
},
"total": {
"value": "104.95",
"currency": "USD"
}
},
"cancelStatus": {
"cancelState": "NONE_REQUESTED",
"cancelRequests": []
},
"paymentSummary": {
"totalDueSeller": {
"value": "104.95",
"currency": "USD"
},
"refunds": [],
"payments": [
{
"paymentMethod": "PAYPAL",
"paymentReferenceId": "G&4EGFTFBFUSD",
"paymentDate": "2018-08-15T16:08:01.000Z",
"amount": {
"value": "104.95",
"currency": "USD"
},
"paymentStatus": "PAID",
"paymentHolds": [
{
"holdReason": "ITEM_PRICE_INELIGIBLE",
"holdAmount": {
"value": "104.95",
"currency": "USD"
},
"holdState": "RELEASE_CONFIRMED",
"releaseDate": "2018-08-15T16:08:01.000Z"
}
]
}
]
},

"fulfillmentStartInstructions": [
{
"fulfillmentInstructionsType": "SHIP_TO",
"minEstimatedDeliveryDate": "2018-08-23T07:00:00.000Z",
"maxEstimatedDeliveryDate": "2018-08-23T07:00:00.000Z",
"ebaySupportedFulfillment": false,
"shippingStep": {
"shipTo": {
"fullName": "Jimmy Bob",
"contactAddress": {
"addressLine1": "123 Beaver STreet",
"city": "Compton",
"stateOrProvince": "CA",
"postalCode": "90210",
"countryCode": "US"
},
"primaryPhone": {
"phoneNumber": "9048675309"
},
"email": "buyer@yahoo.com"
},
"shippingCarrierCode": "UPS",
"shippingServiceCode": "UPSGround"
}
}
],
"fulfillmentHrefs": [],
"lineItems": [
{
"lineItemId": "7937rgh3w7rg",
"legacyItemId": "74hg3hg8hr",
"sku": "6549840001526",
"title": "Gaming PC",
"lineItemCost": {
"value": "104.95",
"currency": "USD"
},
"quantity": 1,
"soldFormat": "FIXED_PRICE",
"listingMarketplaceId": "ecommerce",
"purchaseMarketplaceId": "ecommerce",
"lineItemFulfillmentStatus": "NOT_STARTED",
"total": {
"value": "104.95",
"currency": "USD"
},
"deliveryCost": {
"shippingCost": {
"value": "0.0",
"currency": "USD"
}
},
"appliedPromotions": [],
"taxes": [],
"properties": {
"buyerProtection": true
},
"lineItemFulfillmentInstructions": {
"minEstimatedDeliveryDate": "2018-08-23T07:00:00.000Z",
"maxEstimatedDeliveryDate": "2018-08-23T07:00:00.000Z",
"shipByDate": "2018-08-17T03:59:59.000Z",
"guaranteedDelivery": false
}
}
]
},
]
}

1 ACCEPTED SOLUTION

SanjivMeher
Kilo Patron
Kilo Patron

Can you try

 

var response = smt.execute();
var responseBody = response.getBody();
var statur = response.getStatusCode();
gs.info(JSON.stringify(JSON.parse(responseBody)));

var obj = JSON.stringify(JSON.parse(responseBody, function(key, value) {
if (value != '') {
gs.info(key+'--'+value);
}
}), undefined, 2);


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

5 REPLIES 5

Hi Sanjiv,

 

I need your help regarding the same you have replied above but in my post as follows:

https://community.servicenow.com/community?id=community_question&sys_id=b0fbad05dbbfa78023f4a345ca96194a 

Can you please help me.

 

Regards,

Geet