Hi, my post request here below works fine but the patch doesn't. Does anyone have a solution? Thanks
document.getElementById('home_button').addEventListener('click', async function(event) {
event.preventDefault(); // Stop the default navigation
webapi.safeAjax({
type: "POST",
url: "/_api/cr40e_cogitumtabs",
contentType: "application/json",
data: JSON.stringify({"cr40e_cogitaskname": "hello",}),
success: function(res, status, xhr) { // Moved inside the object
console.log("entityID: " + xhr.getResponseHeader("entityid"));
window.entityID = xhr.getResponseHeader("entityid"); // Store entityID globally
},
error: function(xhr, status, error) { // Moved inside the object
console.error("Error occurred: " + error);
}
});
});
document.getElementById('replay_button').addEventListener('click', function(e) {
e.preventDefault(); // Prevent default form submission
if (!window.entityID) {
console.error("Entity ID is not set. Cannot perform update.");
return;
}
webapi.safeAjax({
type: "PATCH",
url: "/_api/cr40e_cogitumtabs/" + window.entityID, // Append entityID to the URL
contentType: "application/json",
data: JSON.stringify({"cr40e_cogitaskname": "hello - updated",}),
success: function(res) {
console.log("Record updated successfully.");
// Handle further actions after successful update, if necessary
},
error: function(xhr, status, error) {
console.error("Error updating record: " + error);
}
});
});