- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2018 07:06 AM
Hello Everyone,
This is my first API Integration and I'm having a some issues with the JSON Parse to retrieve the properties of the JSON string. When I try to create a new variable from the string and print it, the variable is coming back as undefined. Below is the JSON string I am trying to parse and the script I am using. I am testing this with a background script but will be moving this to a scheduled job.
{"AssetWarrantyResponse": [
{
"AssetHeaderData": {
}, "ProductHeaderData": {
}, "AssetEntitlementData": [
{
"StartDate": "2015-10-25T00:00:00", "EndDate": "2017-10-24T23:59:59", "ServiceLevelDescription": "Onsite Service After Remote Diagnosis (Consumer Customer)/ Next Business Day Onsite After Remote Diagnosis (Commercial Customer)", "ServiceLevelCode": "ND", "ServiceLevelGroup": 5, "EntitlementType": "EXTENDED", "ServiceProvider": "UNY", "ItemNumber": "995-8004" }, {
"StartDate": "2014-10-24T00:00:00", "EndDate": "2015-10-24T23:59:59", "ServiceLevelDescription": "Onsite Service After Remote Diagnosis (Consumer Customer)/ Next Business Day Onsite After Remote Diagnosis (Commercial Customer)", "ServiceLevelCode": "ND", "ServiceLevelGroup": 5, "EntitlementType": "INITIAL", "ServiceProvider": "UNY", "ItemNumber": "995-7974" }, {
"StartDate": "2014-10-24T00:00:00", "EndDate": "2022-10-27T23:59:59", "ServiceLevelDescription": "Dell Digitial Delivery", "ServiceLevelCode": "D", "ServiceLevelGroup": 11, "EntitlementType": "INITIAL", "ServiceProvider": "DELL", "ItemNumber": "421-9983" }, {
"StartDate": "2014-10-24T00:00:00", "EndDate": "2022-10-27T23:59:59", "ServiceLevelDescription": "Dell Digitial Delivery", "ServiceLevelCode": "D", "ServiceLevelGroup": 11, "EntitlementType": "INITIAL", "ServiceProvider": "DELL", "ItemNumber": "422-0007" }, {
"StartDate": "2014-10-24T00:00:00", "EndDate": "2022-10-27T23:59:59", "ServiceLevelDescription": "Dell Digitial Delivery", "ServiceLevelCode": "D", "ServiceLevelGroup": 11, "EntitlementType": "INITIAL", "ServiceProvider": "DELL", "ItemNumber": "421-9982" } ] } ], "InvalidFormatAssets": {
}, "InvalidBILAssets": {
}, "ExcessTags": {
}, "AdditionalInformation": null }
var parser = new JSONParser();
var parsed = parser.parse(responseBody);
var expirationDate = parsed.GetAssetWarrantyResponse.AssetEntitlementData.EndDate;
gs.print(expirationDate);
I should be receiving the value of
"2017-10-24T23:59:59" but I am receiving undefined instead.
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2018 07:46 AM
My Mistake, AssetWarrantyResponse is also array of object.
Try like this -
var parser = new JSONParser();
var parsed = parser.parse(responseBody);
var expirationDate = parsed.AssetWarrantyResponse[0].AssetEntitlementData[0].EndDate;
gs.print(expirationDate);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2018 10:12 AM
This is exactly what I was looking for!
Thank you Nayan!