Hi all DF gurus,
I’m trying to alter the request resource & parameters in a PATCH request but seems out of luck. Please take a look at my code below:
if (event.request.payload.fieldb) {
var filter = “(a = '” + event.resource + “') AND (b = " + event.request.payload.fieldb + “)”;
filter = encodeURIComponent(filter);
platform.api.get(”/url/_table/mytable?fields=id&filter=" + filter, ‘’, function(body, res) {
var json = JSON.parse(body);
var newid = json.resource[0].id;
event.resource = newid;
event.request.parameters = {};
console.log(“request altered”);
})
}
console.log(event.resource);
console.log(event.request.payload);
throw new Error(“dev - debug breakpoint”);
Client fire a PATCH request to “/url/_table/mytable?id_field=fieldc”. In ideal world, if fieldb exists in the request.payload, the script should fire a GET request and overwrite the event.resource, and then remove the parameters (id_field=fieldc), therefore the console.log at the bottom should show the altered resource & payload, but then, this script seems running in asynchronous mode, the 2x console.log at the bottom show first and only then console.log(“event altered”) show.
I’m wondering is there any asynchronous/sync switch that I can use in this case? or there is a more proper way to achieve this?
Thanks in advance.