MSCRM – How to call Rest Service from Plugins

Another link that maybe can help you:

http://code.msdn.microsoft.com/How-to-call-Rest-Service-b0b188df

I hope that you find it useful.

Annunci

CRM2011 – Default Regarding Lookup to PhoneCall in Activities Entity

Today I need to change the default View in my Regarding Lookup in the Task Entity.
I used the following code to set the Regarding Lookup to Phone Call and set the default view.

document.getElementById("regardingobjectid").setAttribute("defaulttype", "4210");
Xrm.Page.getControl("regardingobjectid").setDefaultView("a2d689d1-45a3-4c29-aswsd-802327e67a0d");

With the first line we set the default entity type to Phone Call for the Regarding Lookup dialog. In the second line we set the Regarding Lookup dialog’s view to the ‘Phone Call Lookup View’ using its guid value.

If you do not use this line of code it will default to the ‘My Active Phone Call View’ or whatever you have selected as the default Phone Call view.

CRM2011 – Retrieve all Entities, Update and Publish them

I needed to change an property on all entities in my organitation. The unique way was to open all entites, modify the attribute, save and publish.. but it is a long and boring work and I don’t like this kind of job. I created a small console application that make it. In this article I will show you how to access items in CRM 2011 via new built in WCF webservice. The main code is the following:

IServiceConfiguration<IOrganizationService> orgConfigInfo =
ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(new Uri("http://server/Organization/XRMServices/2011/Organization.svc"));

//Set the credentials
System.Net.NetworkCredential userDefined = new System.Net.NetworkCredential("Username", "Password", "domain");

var creds = new ClientCredentials();
creds.Windows.ClientCredential = userDefined;

using (_serviceProxy = new OrganizationServiceProxy(orgConfigInfo, creds))
{
   RetrieveAllEntitiesRequest request = new RetrieveAllEntitiesRequest()
   {
      EntityFilters = EntityFilters.Entity,
      RetrieveAsIfPublished = true
   };
   // Retrieve the MetaData.
   RetrieveAllEntitiesResponse response = (RetrieveAllEntitiesResponse)_serviceProxy.Execute(request);

   foreach (EntityMetadata currentEntity in response.EntityMetadata)
   {
      currentEntity.IsVisibleInMobile.Value = false;

      UpdateEntityRequest updateEntityRequest = new UpdateEntityRequest();
      updateEntityRequest.Entity = currentEntity;
      _serviceProxy.Execute(updateEntityRequest);
   }

   PublishAllXmlRequest publishRequest = new PublishAllXmlRequest();
   _serviceProxy.Execute(publishRequest);
}

I got all entities, I updated them and at the end I published all modified….. 🙂
The console application is on my Github repository (MsCrm.RetrieveUpdate.ConsoleApplication)