Showing posts with label Soap. Show all posts
Showing posts with label Soap. Show all posts

Wednesday, June 8, 2016

Fetch Child records in MS CRM

function fetchChildRecord() {
    var GUIDvalue = Xrm.Page.data.entity.getId();
    if (GUIDvalue != null) {
        //alert(GUIDvalue);
        var childRec = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
                            "<entity name='contact'>" +
                            " <attribute name='fullname' />" +
                            " <attribute name='parentcustomerid' />" +
                            " <attribute name='telephone1' />" +
                            " <order attribute='fullname' descending='false' />" +
                            " <filter type='and'>" +
                            " <condition attribute='parentcustomerid' operator='eq'  value='" + GUIDvalue + "' />" +
                            " </filter>" +
                            "</entity>" +
                            "</fetch> ";

        var childRecords = XrmServiceToolkit.Soap.Fetch(childRec);
        if (childRecords.length > 0) {
            if (childRecords[0].attributes.status != undefined) {
                var StatusValue = childRecords[0].attributes.fullname.value;
                alert(childRecords[0].attributes.fullname.value);
                //return StatusValue;
            }
        }
    }
}

//Have to add the XrmServiceToolkit.js file 
//links to download the file xrmservicetoolkit/xrmservicetoolkit 

Monday, January 21, 2013

What is REST/SOAP?

What Is REST?

REST represents Representational State Transfer. REST is an architectural style in which every resource is addressed by using a unique URI. In Microsoft Dynamics CRM, a resource can be an entity collection or a record.
REST works the way the Internet works. You interact with resources by using HTTP verbs such as GET , POST , MERGE , and DELETE . Various libraries can be used to process the HTTP requests and responses. REST provides a standard interface that you can use with any programming language. REST allows for either synchronous or asynchronous processing of operations. The capability to perform asynchronous operations makes REST well suited for AJAX and Silverlight clients.
OData sends and receives data by using either ATOM or JavaScript Object Notation (JSON). ATOM is an XML-based format usually used for RSS feeds. JSON is a text format that allows for serialization of JavaScript objects.

Limitations

The REST endpoint provides an alternative to the WCF SOAP endpoint, but there are currently some limitations.
Only Create, Retrieve, Update, and Delete actions can be performed on entity records.
a.Messages that require the Execute method cannot be performed.
b.Associate and disassociate actions can be performed by using navigation properties.
Authentication is only possible within the application.
a.Use of the REST endpoint is limited to JScript libraries or Silverlight web resources.

What Is SOAP?

Unlike the REST endpoint for web resources, the SOAP endpoint uses the Organization service. This is the same service used when writing applications that exist outside of the Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online application. The differences are:
a.Requests are sent to a different URL: <organization URL>/XRMServices/2011/Organization.svc/web.b.Authentication is provided by the application.
Because authentication is provided by the application, you must create web resources in the application before the code that uses the service can operate.

Comparison of Programming Methods

You can use the SOAP endpoint for Web Resources with JScript libraries or by using Microsoft Silverlight. The process for using this endpoint is very different, depending on the technology used.

Using the SOAP Endpoint with JScript

With JScript, you will be using XmlHttpRequest to POST requests to the service. The body of the request must contain the XML appropriate for the message you are using. You must also parse the XML returned in a response. With XmlHttpRequest , it is possible to make synchronous requests. However it is highly recommended to always use asynchronous requests. Because manually configuring each request is very time consuming, it is expected that you will reuse existing libraries or create your own. Microsoft Dynamics CRM 2011 does not provide a comprehensive set of JScript libraries. The specific syntax used when calling JScript libraries depends on how they are designed. Several sample JScript libraries are provided with the Microsoft Dynamics CRM SDK, but these are not intended to represent the only or best library design. The content in the Microsoft Dynamics CRM SDK focuses on helping you create your own libraries.

Thursday, November 8, 2012

Retreive parent record values from child entity lookup


function retrieverecord() {
  if (Xrm.Page.getAttribute("childlookupid").getValue() != null) {
    //acount guid no
    var parentcustomerID = Xrm.Page.data.entity.attributes.get("childlookupid").getValue()[0].id;
    var xml = "<?xml version='1.0' encoding='utf-8'?>" +
    "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" +
    " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
    " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
    GenerateAuthenticationHeader() +
    "<soap:Body>" +
    "<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
    "<entityName>parentEntity</entityName>" +
    "<id>" + parentcustomerID + "</id>" +
    "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>" +
        "<q1:Attributes>" +
            "<q1:Attribute>parentattributevalue[attributenames]</q1:Attribute>" +            
        "</q1:Attributes>" +
    "</columnSet>" +
    "</Retrieve>" +
    "</soap:Body>" +
    "</soap:Envelope>";
    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
    xmlHttpRequest.send(xml);
    var resultXml = xmlHttpRequest.responseXML;

    var errorCount = resultXml.selectNodes('//error').length;

    if (errorCount != 0) {
        var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
        alert(msg);
    }
    //Display the retrieved value.
    else {
        alert(resultXml.selectSingleNode("//q1:parentattributevalue").nodeTypedValue);
        var cost = resultXml.selectSingleNode('//q1:parentattributevalue').nodeTypedValue;
         
       Xrm.Page.getAttribute("childattribute").setValue(parseInt(cost));
//for retreiving the option set text
//resultXml.selectSingleNode('//q1:parentattributevalue').attributes[0].text;
    }
}
}