- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 01:21 AM
Hi Experts,
I have requirement for the Integration between two applications, In service now we have custom table in that we have field called vendor po number, from servicenow to thirdparty we need to send vendor po numbers in json format like below
{
"searchParameter": [
{
"key": "po_numbers",
"values": [
"8000002201-4",
"8000002201-3"
]
}
]
}
and from third party we will be getting the complete order detail of those respective PO numbers and will be updating in our custom table,
one time we need to send 10 PO numbers,
so for this requirement I would need a help for How I can push the data that is PO numbers from our table to json format shown above,
I have created Rest message and provided End point, for testing purpose I had just put the 2 PO numbers manually [
"8000002201-4",
"8000002201-3"]
and I'm able to get the response, but the requirement is to retrieve the PO numbers automatically form the table, 1st time script should pick 10 PO numbers after getting and updating the order detail of those, next time our script should pick the next 10 PO numbers and added to json payload it should continue like this, script should not pick the last updated PO number records.
Kindly help me on this,
Thanks,
Chaithanya
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 02:09 PM
Hi, quick example using incident numbers for populating an array in the format you appear to require,
also turns out that it wasn't necessary to concatenate the string "quotes" into the array as this happens for us.
Hopefully this is a good starting point for you.
var myObject = {};
var myArray = [];
//populate the array
var test = new GlideRecord('incident');
test.setLimit(10);
test.query();
while(test.next()) {
myArray.push(test.number.toString());
}
//Now build out your object format
myObject.searchParameter = [];
myObject.searchParameter[0] = {
"key": "po_numbers",
"values": myArray
};
var parser = new global.JSON();
var str = parser.encode(myObject);
gs.info('myObject ' + str);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 02:16 AM
Hi, based on the details in your post it looks like you need to iterate through the records in a script, pushing the vendor po numbers into an array, and then populate the array (as a string) into your payload. You might need to also concatenate the double quotes with your PO values as you push then into your array, so that the final formatting is correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 06:26 AM
Hi @Tony Chatfield1
I have tried this approach, I'm storing vendor PO numbers in an array, but I'm not getting how to concatenate the PO values,
Below is the screenshot of values
Thanks,
Chaithanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 02:09 PM
Hi, quick example using incident numbers for populating an array in the format you appear to require,
also turns out that it wasn't necessary to concatenate the string "quotes" into the array as this happens for us.
Hopefully this is a good starting point for you.
var myObject = {};
var myArray = [];
//populate the array
var test = new GlideRecord('incident');
test.setLimit(10);
test.query();
while(test.next()) {
myArray.push(test.number.toString());
}
//Now build out your object format
myObject.searchParameter = [];
myObject.searchParameter[0] = {
"key": "po_numbers",
"values": myArray
};
var parser = new global.JSON();
var str = parser.encode(myObject);
gs.info('myObject ' + str);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2023 02:57 AM
Hi @Community Alums ,
Please refer to this thread: https://www.servicenow.com/community/itsm-forum/how-to-send-data-to-third-party-application-from-servicenow/td-p/481867