Here is the same to code to get account record based on
account Id using SOAP request.
function ExecuteRequest(_XML, Message) {
try {
var _ResultXML = null;
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST",
Xrm.Page.context.getServerUrl() + "/XRMServices/2011/Organization.svc/web", false);
xmlhttp.setRequestHeader("Accept", "application/xml, text/xml, */*");
xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlhttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/" + Message);
xmlhttp.send(_XML);
_ResultXML
= xmlhttp.responseXML;
var errorCount = _ResultXML.selectNodes('//error').length;
if (errorCount != 0) {
var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
alert(msg);
_ResultXML
= null;
return _ResultXML;
}
else {
return _ResultXML;
}
}
catch (Err) {
alert(Err);
return;
}
}
function GetAccountName() {
var request = "<s:Envelope
xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'>" +
"<s:Body>" +
"<Retrieve
xmlns='http://schemas.microsoft.com/xrm/2011/Contracts/Services'
xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>" +
"<entityName>account</entityName>" +
"<id>44b1719c-4440-e311-8fae-00221960bc47</id>" +
"<columnSet
xmlns:a='http://schemas.microsoft.com/xrm/2011/Contracts'>" +
"<a:AllColumns>false</a:AllColumns>" +
"<a:Columns
xmlns:b='http://schemas.microsoft.com/2003/10/Serialization/Arrays'>" +
"<b:string>name</b:string>" +
"<b:string>accountnumber</b:string>" +
"</a:Columns>" +
"</columnSet>" +
"</Retrieve>" +
"</s:Body>" +
"</s:Envelope>";
var _ResultXML = ExecuteRequest(request, "Retrieve");
var _AccountName = _ResultXML.selectSingleNode("//a:Attributes").selectSingleNode("//b:value").text;
return _AccountName;
}
You could call GetAccountName function to get account name
like :
Var _Name= GetAccountName();
You could also pass accountId as parameter to GetAccountName
function.
No comments:
Post a Comment