- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2024 12:35 AM - edited ‎08-21-2024 12:36 AM
Hi Team,
I have a JSON :-
{
"orderId": "ORD123456",
"customer": {
"customerId": "CUST789",
"name": "John Doe",
"address": {
"street": "123 Main St",
"city": "New York",
"state": "NY",
"zip": "10001"
},
"contactDetails": {
"email": "johndoe@example.com",
"phone": "+1-555-555-5555"
}
},
"orderItems": [
{
"itemId": "ITEM001",
"description": "Laptop",
"quantity": 1,
"price": 1200.00,
"attributes": {
"color": "Silver",
"warranty": "2 years"
}
},
{
"itemId": "ITEM002",
"description": "Wireless Mouse",
"quantity": 2,
"price": 25.00,
"attributes": {
"color": "Black",
"warranty": "1 year"
}
}
],
"orderStatus": "Shipped",
"shippingDetails": {
"carrier": "UPS",
"trackingNumber": "1Z999AA10123456784",
"expectedDelivery": "2024-08-25"
}
}
I need the "Shipping Carrier" and "Tracking Number" . How to achieve this??
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2024 07:03 AM
Hi RGGuide,
----------- Please Use the below Script ------------------------
// Your JSON object
var orderData = {
"orderId": "ORD123456",
"customer": {
"customerId": "CUST789",
"name": "John Doe",
"address": {
"street": "123 Main St",
"city": "New York",
"state": "NY",
"zip": "10001"
},
"contactDetails": {
"email": "johndoe@example.com",
"phone": "+1-555-555-5555"
}
},
"orderItems": [
{
"itemId": "ITEM001",
"description": "Laptop",
"quantity": 1,
"price": 1200.00,
"attributes": {
"color": "Silver",
"warranty": "2 years"
}
},
{
"itemId": "ITEM002",
"description": "Wireless Mouse",
"quantity": 2,
"price": 25.00,
"attributes": {
"color": "Black",
"warranty": "1 year"
}
}
],
"orderStatus": "Shipped",
"shippingDetails": {
"carrier": "UPS",
"trackingNumber": "1Z999AA10123456784",
"expectedDelivery": "2024-08-25"
}
};
// Extract the "Shipping Carrier" and "Tracking Number"
var shippingCarrier = orderData.shippingDetails.carrier;
var trackingNumber = orderData.shippingDetails.trackingNumber;
// Output the values
gs.print("Shipping Carrier: " + shippingCarrier);
gs.print("Tracking Number: " + trackingNumber);
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2024 11:24 PM
Can you try method 2 :-
var json = {
"orderId": "ORD123456",
"customer": {
"customerId": "CUST789",
"name": "John Doe",
"address": {
"street": "123 Main St",
"city": "New York",
"state": "NY",
"zip": "10001"
},
"contactDetails": {
"email": "johndoe@example.com",
"phone": "+1-555-555-5555"
}
},
"orderItems": [
{
"itemId": "ITEM001",
"description": "Laptop",
"quantity": 1,
"price": 1200.00,
"attributes": {
"color": "Silver",
"warranty": "2 years"
}
},
{
"itemId": "ITEM002",
"description": "Wireless Mouse",
"quantity": 2,
"price": 25.00,
"attributes": {
"color": "Black",
"warranty": "1 year"
}
}
],
"orderStatus": "Shipped",
"shippingDetails": {
"carrier": "UPS",
"trackingNumber": "1Z999AA10123456784",
"expectedDelivery": "2024-08-25"
}
};
var shippingCarrier = json['shippingDetails']['carrier'];
var trackingNumber = json['shippingDetails']['trackingNumber'];
gs.log("Shipping Carrier: " + shippingCarrier);
gs.log("Tracking Number: " + trackingNumber);
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2024 05:44 AM - edited ‎08-21-2024 05:44 AM
Hi @SandeepKSingh ,
Store the JSON in variable.
var obj = ..........(JSON)
To acess,
If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2024 07:03 AM
Hi RGGuide,
----------- Please Use the below Script ------------------------
// Your JSON object
var orderData = {
"orderId": "ORD123456",
"customer": {
"customerId": "CUST789",
"name": "John Doe",
"address": {
"street": "123 Main St",
"city": "New York",
"state": "NY",
"zip": "10001"
},
"contactDetails": {
"email": "johndoe@example.com",
"phone": "+1-555-555-5555"
}
},
"orderItems": [
{
"itemId": "ITEM001",
"description": "Laptop",
"quantity": 1,
"price": 1200.00,
"attributes": {
"color": "Silver",
"warranty": "2 years"
}
},
{
"itemId": "ITEM002",
"description": "Wireless Mouse",
"quantity": 2,
"price": 25.00,
"attributes": {
"color": "Black",
"warranty": "1 year"
}
}
],
"orderStatus": "Shipped",
"shippingDetails": {
"carrier": "UPS",
"trackingNumber": "1Z999AA10123456784",
"expectedDelivery": "2024-08-25"
}
};
// Extract the "Shipping Carrier" and "Tracking Number"
var shippingCarrier = orderData.shippingDetails.carrier;
var trackingNumber = orderData.shippingDetails.trackingNumber;
// Output the values
gs.print("Shipping Carrier: " + shippingCarrier);
gs.print("Tracking Number: " + trackingNumber);
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2024 11:24 PM
Can you try method 2 :-
var json = {
"orderId": "ORD123456",
"customer": {
"customerId": "CUST789",
"name": "John Doe",
"address": {
"street": "123 Main St",
"city": "New York",
"state": "NY",
"zip": "10001"
},
"contactDetails": {
"email": "johndoe@example.com",
"phone": "+1-555-555-5555"
}
},
"orderItems": [
{
"itemId": "ITEM001",
"description": "Laptop",
"quantity": 1,
"price": 1200.00,
"attributes": {
"color": "Silver",
"warranty": "2 years"
}
},
{
"itemId": "ITEM002",
"description": "Wireless Mouse",
"quantity": 2,
"price": 25.00,
"attributes": {
"color": "Black",
"warranty": "1 year"
}
}
],
"orderStatus": "Shipped",
"shippingDetails": {
"carrier": "UPS",
"trackingNumber": "1Z999AA10123456784",
"expectedDelivery": "2024-08-25"
}
};
var shippingCarrier = json['shippingDetails']['carrier'];
var trackingNumber = json['shippingDetails']['trackingNumber'];
gs.log("Shipping Carrier: " + shippingCarrier);
gs.log("Tracking Number: " + trackingNumber);
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/