{ADVANCED XRM DEVELOPMENT} Retrieve country CODE IN JAVASCRIPT in CRM 2013/2015

The below code is SOAP call from JavaScript for retrieving user setting for country code:

HTTP REQUEST
————————————————–
POST https://orgname.crm4.dynamics.com/XRMServices/2011/Organization.svc/web
Content-Type: text/xml; charset=utf-8
SOAPAction: http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/RetrieveMultiple

<s:Envelope xmlns:s=”http://schemas.xmlsoap.org/soap/envelope/”>
  <s:Body>
    <RetrieveMultiple xmlns=”http://schemas.microsoft.com/xrm/2011/Contracts/Services” xmlns:i=”http://www.w3.org/2001/XMLSchema-instance”>
      <query i:type=”a:QueryExpression” xmlns:a=”http://schemas.microsoft.com/xrm/2011/Contracts”>
        <a:ColumnSet>
          <a:AllColumns>false</a:AllColumns>
          <a:Columns xmlns:b=”http://schemas.microsoft.com/2003/10/Serialization/Arrays”>
            <b:string>defaultcountrycode</b:string>
          </a:Columns>
        </a:ColumnSet>
        <a:Criteria>
          <a:Conditions>
            <a:ConditionExpression>
              <a:AttributeName>systemuserid</a:AttributeName>
              <a:Operator>Equal</a:Operator>
              <a:Values xmlns:b=”http://schemas.microsoft.com/2003/10/Serialization/Arrays”>
                <b:anyType i:type=”c:guid” xmlns:c=”http://schemas.microsoft.com/2003/10/Serialization/”>ce4c5141-9941-456b-9007-fbc3c5f02e8e</b:anyType>
              </a:Values>
              <a:EntityName i:nil=”true” />
            </a:ConditionExpression>
          </a:Conditions>
          <a:FilterOperator>And</a:FilterOperator>
          <a:Filters />
        </a:Criteria>
        <a:Distinct>false</a:Distinct>
        <a:EntityName>usersettings</a:EntityName>
        <a:LinkEntities />
        <a:Orders />
        <a:PageInfo>
          <a:Count>0</a:Count>
          <a:PageNumber>0</a:PageNumber>
          <a:PagingCookie i:nil=”true” />
          <a:ReturnTotalRecordCount>false</a:ReturnTotalRecordCount>
        </a:PageInfo>
        <a:NoLock>false</a:NoLock>
      </query>
    </RetrieveMultiple>
  </s:Body>
</s:Envelope>
————————————————–
OutPut In JavaScript
var xml = “” +
“<s:Envelope xmlns:s=\”http://schemas.xmlsoap.org/soap/envelope/\”><s:Body><RetrieveMultiple xmlns=\”http://schemas.microsoft.com/xrm/2011/Contracts/Services\” xmlns:i=\”http://www.w3.org/2001/XMLSchema-instance\”><query i:type=\”a:QueryExpression\” xmlns:a=\”http://schemas.microsoft.com/xrm/2011/Contracts\”><a:ColumnSet><a:AllColumns>false</a:AllColumns><a:Columns xmlns:b=\”http://schemas.microsoft.com/2003/10/Serialization/Arrays\”><b:string>defaultcountrycode</b:string></a:Columns></a:ColumnSet><a:Criteria><a:Conditions><a:ConditionExpression><a:AttributeName>systemuserid</a:AttributeName><a:Operator>Equal</a:Operator><a:Values xmlns:b=\”http://schemas.microsoft.com/2003/10/Serialization/Arrays\”><b:anyType i:type=\”c:guid\” xmlns:c=\”http://schemas.microsoft.com/2003/10/Serialization/\”>ce4c5141-9941-456b-9007-fbc3c5f02e8e</b:anyType></a:Values><a:EntityName i:nil=\”true\”/></a:ConditionExpression></a:Conditions><a:FilterOperator>And</a:FilterOperator><a:Filters/></a:Criteria><a:Distinct>false</a:Distinct><a:EntityName>usersettings</a:EntityName><a:LinkEntities/><a:Orders/><a:PageInfo><a:Count>0</a:Count><a:PageNumber>0</a:PageNumber><a:PagingCookie i:nil=\”true\”/><a:ReturnTotalRecordCount>false</a:ReturnTotalRecordCount></a:PageInfo><a:NoLock>false</a:NoLock></query></RetrieveMultiple></s:Body></s:Envelope>” +
“”;

var xmlHttpRequest = new XMLHttpRequest();

xmlHttpRequest.open(“POST”, Xrm.Page.context.getClientUrl() +”/XRMServices/2011/Organization.svc/web”, false);
xmlHttpRequest.setRequestHeader(“SOAPAction”,”http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/RetrieveMultiple”);
xmlHttpRequest.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8”);
xmlHttpRequest.setRequestHeader(“Accept”, “application/xml, text/xml, */*”);
xmlHttpRequest.setRequestHeader(“Content-Length”, xml.length);
xmlHttpRequest.send(xml);

var resultXml = xmlHttpRequest.responseText;
alert(resultXml);

 

—–

Hope it helps!

Advertisements

One thought on “{ADVANCED XRM DEVELOPMENT} Retrieve country CODE IN JAVASCRIPT in CRM 2013/2015

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s