Showing posts with label SDK. Show all posts
Showing posts with label SDK. Show all posts

Monday, July 5, 2010

Create CrmService with Caller Id

Here is the example to create CrmService:

CrmAuthenticationToken token = new CrmAuthenticationToken();
token.OrganizationName = "org1";
token.AuthenticationType = 0; //Active directory
token.CallerId = userGuid; // impersonate to this user
CrmService pService = new CrmService();
pService.Url = _strServerUrl + "/MSCRMServices/2007/crmservice.asmx";
pService.CrmAuthenticationTokenValue = token;
pService.Credentials = DefaultCredential();

i can create crmService from two type

1. CrmService as web service from mscrmservices\2007
2. Microsoft.Crm.SDK.

to change the callerid i failed to do it if i used Crmservice from webservice.

i test the issue and changing the caller works only if Crmservice from type Microsoft.Crm.Sdk.

thanks,
Rami Heleg,
NetusUp Inc.

Tuesday, September 22, 2009

Update entity Based Micorost CRM SDK

Hi,
This example used to update record in crm 3.0 and crm 4.0 based SDK

//Create crm service
CrmService pService = new CrmService(); // optional to set url

// define entity + fields. mandatory field is key
incident oInc = new incident();
oInc.incidentid = new Key();
oInc.incidentid.Value = new Guid("guid");
oInc.title="my title"

pService.Update(oInc);

update Can get specific entity for instance contact, incident or dynamic entity.
all type of BusinessEntity.

thanks,
Rami Heleg

Monday, September 21, 2009

Create Entity Based Microsoft CRM SDK

Hi,
this example used to create a new record in crm 4,3 based CRM SDK.

//Create CRM Service
CrmService pService = new CrmService(); // optional to set url BusinessEntity

//Define entity and add values..
contact oContact = new contact();
oContact.firstname = "Rami";
oContact.lastname = "Heleg";

//Run method to create the entity.
Guid guid = pService.Create(entity);
//guid of the new record.


Thanks,
Rami Heleg

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