Extension result doesn't contain the same number of elements as the request object. Expected 1, got . Extension returned statusCode 200
I'm running code to create HL segments for an 856. When I run it in test, I get "Extension result doesn't contain the same number of elements as the request object. Expected 1, got . Extension returned statusCode 200" and when I run it with live data I get "TypeError: Cannot read property 'forEach' of undefined". The data I'm testing with is the same in both test mode and enabled. Is there a way in test mode to find exactly where Javascript is erroring?
Here's my script:
function preMap (options) {
// sample code that simply passes on what has been exported
for(let d of options.data){
let counter = 1;
d.ISA.GS.BSN.HLS.forEach((hls) => {
hls['Hierarchical ID Number'] = counter;
counter++;
hls.HLO.forEach((hlo) => {
hlo['Hierarchical ID Number'] = counter;
hlo['Hierarchical Parent ID Number'] = hls['Hierarchical ID Number'];
counter++;
hlo.HLP.forEach((hlp) => {
hlp['Hierarchical ID Number'] = counter;
hlp['Hierarchical Parent ID Number'] = hlo['Hierarchical ID Number'];
counter++;
});
});
});
}
return {
data: options.data,
errors: options.errors,
abort: false,
newErrorsAndRetryData: []
}
}
Here's my JSON input:
{
"data": [
{
"ISA": {
"Authorization Information Qualifier": "00",
"Authorization Information": "",
"Security Information Qualifier": "00",
"Security Information": "",
"Interchange ID Qualifier(ISA05)": "12",
"Interchange Sender ID": "7045875587",
"Interchange ID Qualifier(ISA07)": "07",
"Interchange Receiver ID": "5400110000009",
"Interchange Date": "240304",
"Interchange Time": "0352",
"Repetition Separator": "^",
"Interchange Control Version Number": "00501",
"Interchange Control Number": "109835459",
"Acknowledgment Requested": "0",
"Usage Indicator": "P",
"Component Element Separator": ":",
"GS": {
"Functional Identifier Code": "SH",
"Application Sender's Code": "PPSF",
"Date": "240304",
"Time": "0352",
"Group Control Number": "483",
"Responsible Agency Code": "X",
"Version / Release / Industry Identifier Code": "00501",
"Hierarchical Structure Code": "0001",
"BSN": {
"Reporting Code": "F",
"Depositor Order Number": "51038369",
"Date": "",
"Transaction Set Purpose Code": "00",
"Shipment Identifier": "2094215",
"HLS": [
{
"Hierarchical Level Code": "S",
"TD1": {
"Packing Code": "CTN"
},
"TD5": {
"Identification Code": "CPU",
"Transport Type Code": "H",
"Routing": "CUSTOMER PICK-UP"
},
"DTM": [
{
"Date/Time Qualifier": "02",
"Date": "20240216"
},
{
"Date/Time Qualifier": "10",
"Date": "20240207"
},
{
"Date/Time Qualifier": "52",
"Date": "20240205"
}
],
"N1": [
{
"Entity ID Code": "WH",
"Name": "Distribution Technology",
"ID Code Qualifier": null,
"IDCode": null
},
{
"Entity ID Code": "DE",
"Name": "PETER PAN SEAFOOD CO LLC",
"ID Code Qualifier": null,
"IDCode": null
},
{
"Entity ID Code": "ST",
"Name": "DA DISTRIBUTION, LLC",
"ID Code Qualifier": "91",
"IDCode": "0034485600011"
}
],
"N3": {
"Address": "2110 EXECUTIVE BLVD"
},
"N4": {
"City": "SALISBURY",
"State": "NC",
"Postal Code": "28144"
},
"HLO": [
{
"Hierarchical Level Code": "O",
"PRF": {
"PO Number": " 11638369"
},
"HLP": [
{
"Hierarchical Level Code": "P",
"LIN": {
"Assigned Number": "000001",
"Product/Service ID Qualifier": "UA",
"Product/Service ID": "01505"
},
"SN1": {
"Assigned Number": "000001",
"Number of Units Shipped": "28",
"Unit/Basis Measures Code": "CA"
},
"MAN": {
"Marks and Numbers Qualifier": "UC"
}
}
]
}
]
}
]
}
}
}
}
],
"configuration": {},
"_importId": "65c51d2dc1c1a270840d0589",
"_connectionId": "65ba9c1189fca84e68b5398f",
"_flowId": "65a69c8694c634493f21ebb0",
"_integrationId": "65a699775819e037ed446c60",
"settings": {
"integration": {},
"flowGrouping": {},
"flow": {},
"import": {},
"connection": {}
},
"testMode": true
}
0
Comments
Jack Harris are you saying the input JSON here is from the input section of test mode and this same input data fails in test mode, but works in preview?
Jack Harris from the looks of it, the output of your script is invalid. What you have is returning in the format of a preSavePage script and not a preMap script. The function stub will say what needs to be returned.
See your output:
Correct output:
Please sign in to leave a comment.