- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2022 10:13 PM
Hi all,
I have question on Integration. I am using Scripted REST API to consume the data on ServiceNow system.
Below is the sample payload. I am able to get the individual attributes like Name, country etc and able to map with target fields on ServiceNow. I need the entire Contact info object in one attribute. It has email and businessunit fields need to capture in single field. How to get the Contact info object?
{
"BusinessAccount": {
"PrimaryAccount": {
"Name": "test",
"country": "GB",
"Contact info": {
"email": "test@gmail.com",
"businessUnit": "GB01"
}
}
}
}
Thanks,
Pavan
Solved! Go to Solution.
- Labels:
-
Customer Service Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2022 11:40 PM
Hi,
are you saying you want to store the json string into some string field?
if yes then do this
var json = '{"BusinessAccount":{"PrimaryAccount":{"Name":"test","country":"GB","Contact info":{"email":"test@gmail.com","businessUnit":"GB01"}}}}';
var parser = JSON.parse(json);
var contactInfo = JSON.stringify(parser.BusinessAccount.PrimaryAccount["Contact info"]);
gs.info(contactInfo);
Output:
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2022 10:31 PM
Hi,
contact Info object has 2 information within it i.e. email and businessUnit
So you can get those individually but you need to decide which target field of the table will hold that information
regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2022 10:41 PM
Hi,
sample script to fetch the details
var json = '{"BusinessAccount":{"PrimaryAccount":{"Name":"test","country":"GB","Contact info":{"email":"test@gmail.com","businessUnit":"GB01"}}}}';
var parser = JSON.parse(json);
var contactEmail = parser.BusinessAccount.PrimaryAccount['Contact info'].email;
var contactBusinessUnit = parser.BusinessAccount.PrimaryAccount['Contact info'].businessUnit;
gs.info(contactEmail);
gs.info(contactBusinessUnit);
Output:
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2022 11:26 PM
Hi,
Individual attributes I can get. I need to get the entire object of "Contact info" as given below. both email and businessunit fields need to stored in a single variable.
"Contact info": {
"email": "test@gmail.com",
"businessUnit": "GB01"
}
Thanks,
Pavan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2022 11:40 PM
Hi,
are you saying you want to store the json string into some string field?
if yes then do this
var json = '{"BusinessAccount":{"PrimaryAccount":{"Name":"test","country":"GB","Contact info":{"email":"test@gmail.com","businessUnit":"GB01"}}}}';
var parser = JSON.parse(json);
var contactInfo = JSON.stringify(parser.BusinessAccount.PrimaryAccount["Contact info"]);
gs.info(contactInfo);
Output:
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
