So, I will cut this very short, because my patience and my tolerance for things not working correctly is basically gone at this point. According to the documentation, I can modify data before it hits an API / Database, such as scrubbing SSN numbers, by using a Pre-Process server-side script. However, no matter what I do in a Pre-Process script, the call never does what it should; it always complains about a field missing, or data missing, even though they are obviously there from the script (a small sample below).
if (event.request.payload.resource) {
// Go through each record and modify appropriately
if (event.request.payload.resource.length && event.request.payload.resource.length >= 1) {
event.request.payload.resource.forEach((record, idx) => {
// Placeholder for the actual request detail
let request = {};
// Pull data from the API request and format appropriately
request.JO = record.so.jobOrder;
request.PanelNo = record.ps.panelNo;
// This reassignment works, as I see it correct in the below console.log statements
event.request.payload.resource[idx] = request;
console.log(record);
console.log(event.request.payload);
});
}
}
According to console.log, here is what I now have:
{
resource: [
{
JO: '2',
PanelNo: '4',
DR: '5',
FK_WorkStatusId: 200
}
]
}
However, according to the error I get back from the DreamFactory API when trying to post, this is not what the data looks like at all:
{
"error": {
"code": 1000,
"context": {
"error": [
0
],
"resource": [
{
"code": 400,
"context": null,
"message": "Required field 'fk_workstatusid' can not be NULL.",
"status_code": 400
}
]
},
"message": "Batch Error: Not all requested records could be created.",
"status_code": 500
}
}
NOTE: The lowercase/uppercase naming of the field is meaningless, as adding a second field with the lowercase name still results in this error message. From what I gather, the technique shown in the documentation seems to have problems with accurately working.
NOTE: Here is the sample from DF [https://wiki.dreamfactory.com/DreamFactory/Tutorials/V8_field_scrambling]
NOTE: The script is Active
NOTE: The script is allowed to modify the request payload
NOTE: If I take the data from the console.log statement, and put it into Insomnia or another tool, I can post to the database using the same API without issue, which IMO indicates an issue with this feature to modify an incoming request during POST
Any ideas?