Hello!
I'm using the Web API in Power Apps Portals to create a new record upon click of a button, then I'm trying to get it to call a second function passing the guid of the new record, so I can relate records from another table (N:N).
The problem is that my response always comes back successful (and it is, the record is created properly) but empty. I seem to get a 204- no content response each time, so I can't get the GUID of the record I just created. I have tried getting all details of the response (res, status, xhr) but everything comes back undefined or null. If anyone could offer some advice that would be great!
Here is my code:
{% include 'AJAX Wrapper' %}
<script>
//Create Invoice
function createInvoice() {
webapi.safeAjax({
type: "POST",
Accept: "application/json",
url: "/_api/obj_invoices",
contentType: "application/json",
data: JSON.stringify({
"obj_subtotal": subtotalValue,
"obj_Registration@odata.bind": "/cref8_registrations({{ request.params.id }})",
"obj_CompetitionLocation@odata.bind": "/cref8_competitionlocations({{ request.params.compLoc }})",
"obj_Account@odata.bind": "/accounts({{ request.params.acc }})"
}),
success: function (res, status, xhr) {
let newInvoice = xhr.getResponseHeader("obj_invoiceid");
relateDiscounts(newInvoice);
console.log(res);
}
});
}
function relateDiscounts(InvoiceID) {
for (let x in discount_array){
webapi.safeAjax({
type: "POST",
Accept: "application/json",
url: "/_api/obj_invoices(" + InvoiceID + ")/obj_Invoice_obj_Discounts_obj_Discounts/$ref",
contentType: "application/json",
data: JSON.stringify({
"@odata.id":"/_api/obj_discountses(" + discount_array[x] + ")"
}),
success: function (res, status, xhr) {
console.log("entityID: "+ xhr.getResponseHeader("obj_discountsid"))
}
})
};
};
</script>
Solved! Go to Solution.
according to the documentation, you should put "entityid" for the getResponseHeader, so the code should be
let newInvoice = xhr.getResponseHeader("entityid");
the parameters of success do not contain directly the headers, but you can see the response headers of the call under the Network tab of Browser developers tools (press F12).
so if entityid doesn't work, press F12, go to Network, recall your page and the call to /_api/obj_invoices will appear and see the response headers you are receiving.
If after this test you can report your findings here I am interested regarding this. thanks
according to the documentation, you should put "entityid" for the getResponseHeader, so the code should be
let newInvoice = xhr.getResponseHeader("entityid");
the parameters of success do not contain directly the headers, but you can see the response headers of the call under the Network tab of Browser developers tools (press F12).
so if entityid doesn't work, press F12, go to Network, recall your page and the call to /_api/obj_invoices will appear and see the response headers you are receiving.
If after this test you can report your findings here I am interested regarding this. thanks
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
User | Count |
---|---|
7 | |
4 | |
2 | |
2 | |
1 |