November 15, 2024

OData endpoint

CRM fornisce nativamente un endpoint di tipo OData attraverso il quale è possibile interagire con differenti librerie Javascript:

  • Ajax
  • JQuery
  • ..

Ajax:

è una tecnica per sviluppare applicazioni altamente dinamiche fondendo insieme le caratteristiche di HTML e JavaScript utilizzando l’oggetto XMLHttpRequest per la manipolazione dei dati.

La novità di AJAX rispetto ad altre tecniche è che consente alla pagina di interagire con risorse esterne, ad esempio database o file XML, incorporando il risultato dell’elaborazione direttamente nella pagina stessa senza che sia necessario ricaricarla. Questa caratteristica migliora l’interazione dell’utente con il sito ed incrementa la velocità di caricamento, consentendo di realizzare applicazioni web molto simili a strumenti software per desktop.

di seguito un esempio di chiamata a OData con Ajax:

var account = {};
    account.Name = “Sample Account”;
    var jsonAccount = JSON.stringify(account);

    var createAccountReq = new XMLHttpRequest();
    createAccountReq.open(“POST”, Xrm.Page.context.getClientUrl() + “/XRMServices/2011/OrganizationData.svc/AccountSet”, true);
    createAccountReq.setRequestHeader(“Accept”, “application/json”);
    createAccountReq.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);
    createAccountReq.onreadystatechange = function () {
        createAccountReqCallBack(this);
    };
    createAccountReq.send(jsonAccount);

function createAccountReqCallBack(createAccountReq) {
    if (createAccountReq.readyState == 4 /* complete */) {
        createAccountReq.onreadystatechange = null; //avoids memory leaks
        if (createAccountReq.status == 201) {
            //Success
            var newAccount = JSON.parse(createAccountReq.responseText).d;
        }
        else {
            //Failure
            errorHandler(createAccountReq);
        }
    }
};

 

JQuery:

jQuery è un framework realizzato in Javascript per la programmazione di script lato client proprio attraverso il linguaggio con cui è stato realizzato. Grazie a jQuery è possibile realizzare, attraverso pochissime righe di codice, script altrimenti molto complessi che consentono di creare effetti su testo, immagini, controlli di varia natura e di interagire in modo semplice e diretto con i CSS, con AJAX e cosi via.

di seguito un esempio di chiamata a OData con JQuery:

  var account = {};
    account.Name = “Sample Account”;
    var jsonAccount = window.JSON.stringify(account);
    $.ajax({
        type: “POST”,
        contentType: “application/json; charset=utf-8”,
        datatype: “json”,
        url: Xrm.Page.context.getClientUrl() + “/XRMServices/2011/OrganizationData.svc/AccountSet”,
        data: jsonAccount,
        beforeSend: function (XMLHttpRequest) {
            //Specifying this header ensures that the results will be returned as JSON.
            XMLHttpRequest.setRequestHeader(“Accept”, “application/json”);
        },
        success: function (data, textStatus, XmlHttpRequest) {
            account = data.d;
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            errorHandler(XMLHttpRequest, textStatus, errorThrown);
        }
    });

 

 

 

 

 

 

 

 

About The Author

Founder & CEO of Logol AG www.logol.com Microsoft MVP Business Solutions Active member of Scrum Alliance with the certifications CSM and CSP I got Microsoft MCP, MCPD, MCTS certifications as well.Logol, pioneering specialist in the field of cloud-enabled digital transformation, is the first operator specifically created to implement modular programs designed to unleash breakthrough innovation and rationalize business processes. Founded and directed by an award-winning expert tapping directly into the vision of leading IT companies and spearheading forward-thinking digitalization projects, Logol addresses the needs of enterprises in all sectors as they embrace new technologies and organizational change in the era big data and artificial intelligence. Logol helps organizations leverage the power of the most advanced cloud technologies, offering end-to-end consultancy for total digital transformation and business process automation, employing agile methodologies and change management techniques for smooth transitions towards new business paradigms. Digital transformation programs are a milestone in a company’s business evolution and can be the basis of their success. Accompanying clients as they transform their business processes, Logol assists them in rethinking not only the scope of their technologies, but also the strategy, mindset and company culture that make digital transformation viable and effective. As digital transformation programs are successful only if approached with the highest professional competence, Logol selects and employs brilliant professionals who demonstrate outstanding technical expertise in the most advanced information technologies, in depth strategic knowledge of business processes and innovation, and refined soft skills to better support people and organizations facing change. Logol is headquartered in Switzerland and addresses the needs of both public and private sector players by promoting a comprehensive and proactive approach to digital transformation as a necessary step for inclusion and competitiveness in today’s digital economy.

Related posts