Wednesday, May 21, 2014

Find account attributes based on account Id using SOAP request MS CRM 2011 and MS CRM 2013

I need to retrieve all the attribute from account entity based on  accountID.

sample code given below:

 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(accountID) {
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>"+ accountID +"</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;
}

Read all Notes having attachment related to case entity in MS CRM 2011 and MS CRM 2013

Here is the sample code.

public static EntityCollection GetAllNotes(Guid CaseId, IOrganizationService service)
{
EntityCollection results = null;
try
{

QueryExpression Query = new QueryExpression
{
EntityName = "annotation",
ColumnSet = new ColumnSet("filename""documentbody""filesize""mimetype","isdocument"),
Criteria = new FilterExpression
{
FilterOperator = LogicalOperator.And,

Conditions =
{
new ConditionExpression
{
AttributeName = "objectid",
Operator = ConditionOperator.Equal,
Values = { CaseId }
},
new ConditionExpression
{
AttributeName = "isdocument",
Operator = ConditionOperator.Equal,
Values = { true }
},
}
}
};

results = service.RetrieveMultiple(Query);

}
catch (Exception Ex)
{
Console.Write(Ex.Message);
if (Ex.InnerException != null)
{
Console.WriteLine(Ex.InnerException.Message);
Console.ReadLine();
}
}
return results;

}

How to get/set Form header field in MS CRM 2011 and MS CRM 2013 !!!

There is no supported method in SDK to get and set form header field value using JavaScript. However, there is a workaround to achieve this just place field in Form Header and Form as well (You can hide field from Form in case of you don’t want to show the user). Then you can get and set the field values.

// to get field value
var Value=Xrm.Page.data.entity.attributes.get("new_field").getValue();

// to set field valuenew_field
Xrm.Page.data.entity.attributes.get("new_field").setValue(100);

Split the String values with a special character in MS Flow to convert this into Array

 Many times we have a requirement to prepare the Mailing address for some of the documents, suppose there are Address Line1, Address Line2, ...