locked
Check value on other forms/entity RRS feed

  • Question

  • Hi,

    When opening an opportunity, the system has to check some values on the account form.
    I know i can get values with javacript if it is on the same form(Xrm.Page.getAttribute('..').getValue() ),

    but how can i check a value that is not on the form?

    Thanks!

    Friday, July 18, 2014 12:17 PM

Answers

  • Hi Alexander,

    When you need a record from the database you need to do it through the CRM web service endpoints.

    One of them is the odata service. See below a sample function on how to return and entity object by guid.

    var returnObject = new Object();

    function returnEntityObjectByGuid(entity, eId) {

        var oDataPath = Xrm.Page.context.getServerUrl() + "/xrmservices/2011/organizationdata.svc";
        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: "json",
            url: oDataPath + "/" + entity + "Set" + "(guid'" + eId + "')",
            beforeSend: function (XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("Accept", "application/json");
            },
            success: function (data, textStatus, XmlHttpRequest) {
                returnObject = data.d;

            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                // alert(errorThrown);
                returnObject = null;
            },
            async: false
        });
        return returnObject;
    }

    To use this function you will need jquery and json libraries loaded into the form. If you are using crm 2013 they might be loaded by default, if they are not,download them and add them as web resources on the form. The function will return and entity object for the GUID, in which you can check the values of the fields and manipulate them.

    For more information on what you can do with oData and how you can read on http://msdn.microsoft.com/en-us/library/gg309461.aspx

    I'd suggest you to install following solution on your organization, so you get a better feel on what kind of oData queries you can build.

    http://crm2011odatatool.codeplex.com/

    When using odata the entity attribute names are used with the Schema names, so be careful around that.

    There are also libraries like http://xrmservicetoolkit.codeplex.com/ which you have ready functions to use with oData.

    Hope it helps.

    Bojan.

    Monday, July 21, 2014 2:12 PM

All replies

  • Hi Alexander,

    When you need a record from the database you need to do it through the CRM web service endpoints.

    One of them is the odata service. See below a sample function on how to return and entity object by guid.

    var returnObject = new Object();

    function returnEntityObjectByGuid(entity, eId) {

        var oDataPath = Xrm.Page.context.getServerUrl() + "/xrmservices/2011/organizationdata.svc";
        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: "json",
            url: oDataPath + "/" + entity + "Set" + "(guid'" + eId + "')",
            beforeSend: function (XMLHttpRequest) {
                XMLHttpRequest.setRequestHeader("Accept", "application/json");
            },
            success: function (data, textStatus, XmlHttpRequest) {
                returnObject = data.d;

            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                // alert(errorThrown);
                returnObject = null;
            },
            async: false
        });
        return returnObject;
    }

    To use this function you will need jquery and json libraries loaded into the form. If you are using crm 2013 they might be loaded by default, if they are not,download them and add them as web resources on the form. The function will return and entity object for the GUID, in which you can check the values of the fields and manipulate them.

    For more information on what you can do with oData and how you can read on http://msdn.microsoft.com/en-us/library/gg309461.aspx

    I'd suggest you to install following solution on your organization, so you get a better feel on what kind of oData queries you can build.

    http://crm2011odatatool.codeplex.com/

    When using odata the entity attribute names are used with the Schema names, so be careful around that.

    There are also libraries like http://xrmservicetoolkit.codeplex.com/ which you have ready functions to use with oData.

    Hope it helps.

    Bojan.

    Monday, July 21, 2014 2:12 PM
  • Thanks! I will try this out :)

    Wednesday, July 23, 2014 7:58 AM