Hi,
I'm trying to make an update from a web page in a table in dataverse from my custom portal when I select a panel, but I'm getting always the error: "shell is not defined" in the wrapper function.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<link rel="icon" type="image/x-icon" href="../favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="~/style.css">
<script src="~/jquery.min.js"></script>
<script>
(function (webapi, $) {
function safeAjax(ajaxOptions) {
var deferredAjax = $.Deferred();
shell.getTokenDeferred().done(function (token) {
// add headers for AJAX
if (!ajaxOptions.headers) {
$.extend(ajaxOptions, {
headers: {
"__RequestVerificationToken": token
}
});
} else {
ajaxOptions.headers["__RequestVerificationToken"] = token;
}
$.ajax(ajaxOptions)
.done(function (data, textStatus, jqXHR) {
validateLoginSession(data, textStatus, jqXHR, deferredAjax.resolve);
}).fail(deferredAjax.reject); //AJAX
}).fail(function () {
deferredAjax.rejectWith(this, arguments); /*on token failure pass the token AJAX and args*/
});
return deferredAjax.promise();
}
webapi.safeAjax = safeAjax;
})(window.webapi = window.webapi || {}, jQuery)
</script>
<script>
$(document).ready(function () {
sidepanel.on('click', '.js-evt-save', function () {
var dataObject = {
"new_field1": 1,
"new_field2": 2
};
webapi.safeAjax({
type: "PATCH",
url: "/_api/new_myentity(549b6ebf-00f6-eb11-94ee-000d3ab2493f)",
contentType: "application/json",
data: JSON.stringify(dataObject),
success: function (res) {
debugger;
console.log(res)
},
error: function (xhr) {
debugger;
}
});
})
})
</script>
the portal version is: 9.3.7.14 and I already created the web role, entity permission and settings.
I tried with the wrapper inside the $(document).ready but nothing works.
I'm not logged in the portal, I'm as anonymous. Can be it a problem ?
Has anyone had the same problem ?
Thanks in advance