Wednesday, July 8, 2009

Get Attribute Picklist Value

An Example of getting picklist option label:

string entityTypeName = "contact";
string columnName= "new_sex";
string columnValue= "mail";
RetrieveAttributeRequest request = new RetrieveAttributeRequest();
request.EntityLogicalName = entityTypeName;
request.LogicalName = columnName;
RetrieveAttributeResponse response = (RetrieveAttributeResponse)metadataService.Execute(request);
PicklistAttributeMetadata attribute = (PicklistAttributeMetadata)response.AttributeMetadata;
for (int i = 0; i < attribute.Options.Length; i++)
if (attribute.Options[i].Value.Value == ConvertorUtils.ToInt(columnValue))
return attribute.Options[i].Label.ToString();
return "";
}
Enjoy,
Rami Heleg.

Get Entity Type Code - server side

Getting entity type code via metadata service
an Example for CRM 4.0

string entityTypeName = "contact";
RetrieveAllEntitiesRequest request = new RetrieveAllEntitiesRequest();
request.MetadataItems = MetadataItems.EntitiesOnly;
RetrieveAllEntitiesResponse response = (RetrieveAllEntitiesResponse)metadataService.Execute(request);
CrmMetadata[] Metadata = response.CrmMetadata;
foreach (EntityMetadata meta in Metadata) {
if (meta.LogicalName == entityTypeName)
return meta.LogicalName;
}

Enjoy,
Rami Heleg

Get Entity Type Name - server side

Getting entity type name via metadata service
an Example for CRM 4.0

int entityTypeCode = 2;
RetrieveAllEntitiesRequest request = new RetrieveAllEntitiesRequest();
request.MetadataItems = MetadataItems.EntitiesOnly;
RetrieveAllEntitiesResponse response = (RetrieveAllEntitiesResponse)metadataService.Execute(request);
CrmMetadata[] Metadata = response.CrmMetadata;
foreach (EntityMetadata meta in Metadata) {
if (meta.ObjectTypeCode.Value == entityTypeCode)
return meta.LogicalName;
}

Enjoy,
Rami Heleg

Saturday, July 4, 2009

Get Incident Details via Javascript

Hi,
here is an example to get incident details from server only from javascript side

function GetIncidentDetails(IncidentId) {
var xml = "" +
"" +
GenerateAuthenticationHeader() +
" " +
" " +
" " +
" " + "incident" + "" +
" " +
"
" +
" false" +
" " +
" And" +
" " + "incidentidEqual" + incidentId + "" +
"
" +
"
" +
"
" +
"
" +
"
" +
"";
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
var resultXml = xmlHttpRequest.responseXML;
var entityNode = resultXml.selectSingleNode("//RetrieveMultipleResult/BusinessEntities");
return entityNode;
}

Enjoy,
Rami Heleg.

Get Contact Details from Javascript

function GetContactDetails(contactId) {
var xml = "" +
"" +
GenerateAuthenticationHeader() +
" " +
" " +
" " +
" " + "contact" + "" +
" " +
"
" +
" false" +
" " +
" And" +
" " + "contactidEqual" + contactId + "" +
"
" +
"
" +
"
" +
"
" +
"
" +
"";
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
var resultXml = xmlHttpRequest.responseXML;
var entityNode = resultXml.selectSingleNode("//RetrieveMultipleResult/BusinessEntities");
return entityNode;
}

Hide buttons in menu bar

Hi,
Here is an example how to hide buttons in crm menu bar

function FideButton(buttonName){
var list = document.all.tags('SPAN');
for (var i = 0; i < list.length; i++) {
if (list[i].className.indexOf('ms-crm-Menu-Label') >= 0)
if ((list[i].title == buttonName || list[i].innerText == buttonName))
list[i].style.display = 'none';
}
}

Enjoy,
Rami Heleg.