From af825de279591ad34bc2fed9d3be7e748f3b4288 Mon Sep 17 00:00:00 2001 From: "Oleksandr Olashyn (dancingwithcrm)" Date: Tue, 19 Apr 2022 23:14:09 -0400 Subject: [PATCH] Added support for Read operation. Added error handlers --- Xrm.Portal.js | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/Xrm.Portal.js b/Xrm.Portal.js index fdf3361..d940cee 100644 --- a/Xrm.Portal.js +++ b/Xrm.Portal.js @@ -31,7 +31,8 @@ var PortalWebAPI = { Verb: { POST: 'POST', PATCH: 'PATCH', - DELETE: 'DELETE' + DELETE: 'DELETE', + GET: 'GET' } } @@ -39,30 +40,51 @@ var Xrm = Xrm || {}; Xrm.Portal = { WebAPI: { - createRecord: function (datasetName, data, successCallback) { + createRecord: function (datasetName, data, successCallback, errorCallback) { webapi.safeAjax({ type: PortalWebAPI.Verb.POST, url: `${PortalWebAPI.Url}${datasetName}`, contentType: "application/json", data: JSON.stringify(data), - success: function(r, s, x) { successCallback(x); } + success: function(r, s, x) { successCallback(x); }, + error: function (xhr, status, error) { if(errorCallback) { errorCallback(xhr); }; } }); }, - updateRecord: function (datasetName, id, data, successCallback) { + updateRecord: function (datasetName, id, data, successCallback, errorCallback) { webapi.safeAjax({ type: PortalWebAPI.Verb.PATCH, url: `${PortalWebAPI.Url}${datasetName}(${id})`, contentType: "application/json", data: JSON.stringify(data), - success: function(r) { successCallback(r); } + success: function(r) { successCallback(r); }, + error: function (xhr, status, error) { if(errorCallback) { errorCallback(xhr); }; } }); }, - deleteRecord: function (datasetName, id, successCallback) { + deleteRecord: function (datasetName, id, successCallback, errorCallback) { webapi.safeAjax({ type: PortalWebAPI.Verb.DELETE, url: `${PortalWebAPI.Url}${datasetName}(${id})`, contentType: "application/json", - success: function(r) { successCallback(r); } + success: function(r) { successCallback(r); }, + error: function (xhr, status, error) { if(errorCallback) { errorCallback(xhr); }; } + }) + }, + retrieveMultipleRecords: function (datasetName, options, successCallback, errorCallback) { + webapi.safeAjax({ + type: PortalWebAPI.Verb.GET, + url: `${PortalWebAPI.Url}${datasetName}${options}`, + contentType: "application/json", + success: function(r) { successCallback(r); }, + error: function (xhr, status, error) { if(errorCallback) { errorCallback(xhr); }; } + }) + }, + retrieveRecord: function (datasetName, id, options, successCallback, errorCallback) { + webapi.safeAjax({ + type: PortalWebAPI.Verb.GET, + url: `${PortalWebAPI.Url}${datasetName}(${id})${options}`, + contentType: "application/json", + success: function(r) { successCallback(r); }, + error: function (xhr, status, error) { if(errorCallback) { errorCallback(xhr); }; } }) } },