Issue with json data conversion
I am converting a json dataset to a datashape using this code but it returns an empty infotable:
let transformData = function (input) {
try {
const transformedData = {
fieldDefinitions: {},
data: []
};
// Iterate over each record in the input data
input.records.forEach(function(record, index) {
// Create the field definitions (same as before)
transformedData.fieldDefinitions["occurence_" + index] = {
name: "occurence",
aspects: { isPrimaryKey: false },
description: "",
baseType: typeof record.Occurence__c === 'number' ? "NUMBER" : "STRING",
ordinal: 4
};
transformedData.fieldDefinitions["productCode_" + index] = {
name: "productCode",
aspects: { isPrimaryKey: false },
description: "",
baseType: "STRING",
ordinal: 2
};
transformedData.fieldDefinitions["errorCode_" + index] = {
name: "errorCode",
aspects: { isPrimaryKey: false },
description: "",
baseType: "STRING",
ordinal: 3
};
transformedData.fieldDefinitions["id_" + index] = {
name: "id",
aspects: { isPrimaryKey: true },
description: "",
baseType: "GUID",
ordinal: 1
};
transformedData.fieldDefinitions["timeFrame_" + index] = {
name: "timeFrame",
aspects: { isPrimaryKey: false },
description: "",
baseType: "STRING",
ordinal: 5
};
// Push the actual data values into the "data" array
transformedData.data.push({
occurence: record.Occurence__c,
productCode: record.Product_Code__c,
errorCode: record.Error_Code__c,
id: record.Id,
timeFrame: record.Timeframe__c
});
});
return transformedData;
} catch (err) {
logger.error("Problem data conversion: " + err);
}
};
const result = transformData(inputData);
logger.debug(JSON.stringify(result, null, 2));
The input json is
{ "headers": { "Authorization": "Bearer xxxxx", "Accept": "application/json", "Content-Type": "application/json" }, "totalSize": 2, "records": [ { "Timeframe__c": "24h", "Product_Code__c": "12-4300-00", "Type__c": "Critical", "attributes": { "type": "Error_Codes__c", "url": "/services/data/v57.0/sobjects/Error_Codes__c/a39KI000000GyDMYA0" }, "Id": "a39KI000000GyDMYA0", "Error_Code__c": "0-122", "Occurence__c": 1 }, { "Timeframe__c": "Immediate", "Product_Code__c": "12-4100-00", "Type__c": "Critical", "attributes": { "type": "Error_Codes__c", "url": "/services/data/v57.0/sobjects/Error_Codes__c/a39KI000000H0kPYAS" }, "Id": "a39KI000000H0kPYAS", "Error_Code__c": "0-1303", "Occurence__c": 1 } ], "done": true }
please help

