My blog has moved!

Please visit
http://crmdude.wordpress.com/
and update your bookmarks.

Love, Peace and Microsoft CRM

Sunday, 13 September 2009

Moving Blog!

Hi, I'm moving my blog to http://crmdude.wordpress.com/, please update your bookmarks.

Shafraz

Thursday, 20 August 2009

Querying a PartyList field

CRM doesn't allow a PartyList field to be queried using a QueryExpression (it doesn't allow it using Advanced Find either). A colleague had tried to query the Campaign Response records to ascertain whether a Contact had responded to a Campaign before before performing some other process(es).

The trick was to query the Activity Pointer entity (where the regardingobjectid is the Campaign) and then perform a link to the Activity Party entity (where the party is the Contact). The following function shows this:


private static bool AlreadyResponded(string strCampaignId, string strCustomerId)
{
ConditionExpression condition = new ConditionExpression();
condition.AttributeName = "regardingobjectid";
condition.Operator = ConditionOperator.Equal;
condition.Values = new object[] { strCampaignId };

FilterExpression filter = new FilterExpression();
filter.Conditions = new ConditionExpression[] { condition };
filter.FilterOperator = LogicalOperator.And;

# region link to the Activity Party entity
LinkEntity link = new LinkEntity();
link.LinkFromEntityName = EntityName.activitypointer.ToString();
link.LinkToEntityName = EntityName.activityparty.ToString();
link.LinkFromAttributeName = "activityid";
link.LinkToAttributeName = "activityid";

ConditionExpression linkCondition = new ConditionExpression();
linkCondition.AttributeName = "partyid";
linkCondition.Operator = ConditionOperator.Equal;
linkCondition.Values = new object[] { strCustomerId };

FilterExpression linkFilter = new FilterExpression();
linkFilter.Conditions = new ConditionExpression[] { linkCondition };
linkFilter.FilterOperator = LogicalOperator.And;

link.LinkCriteria = linkFilter;
# endregion

QueryExpression query = new QueryExpression();
query.ColumnSet = new AllColumns();
query.Criteria = filter;
query.EntityName = EntityName.activitypointer.ToString();
query.LinkEntities = new LinkEntity[] { link };

BusinessEntityCollection collection = crm.RetrieveMultiple(query);

if (collection != null && collection.BusinessEntities.Length > 0)
return true;

return false;
}

Monday, 15 June 2009

Consuming the MS CRM Web Service for a Secondary Organisation

If you've got multiple CRM organisations in a MS CRM instance, you would have noticed that connecting to the default Web Service gives you only the customisations of the default organisation. In the past, I've been downloading the WSDL files in the Customisation section for each of my secondary organisations and then creating a Web Service reference to the downloaded file- especially annoying when you make changes to your customisation and have to keep the file updated!

Well, I was about to do the same this morning.. until I discovered realised that I could simply consume the download URL of the WSDL file itself:

http://SERVERNAME/MSCrmServices/2007/CrmServiceWsdl.aspx?uniquename=ORGANISATION

Why didn't I discover this before?

Friday, 3 April 2009

Setting a lookup value to null

To set a lookup field to null you'd do the following in your c# code:

vehicle.new_accountid = new Lookup();
vehicle.new_accountid.IsNull = true;
vehicle.new_accountid.IsNullSpecified = true;

To do the same using JavaScript, you'd do the following:

crmForm.all.new_accountid.DataValue = null;

Monday, 2 March 2009

Debugging Custom Workflows

Debugging a custom Workflow that you've written (and registered to your Microsoft CRM instance) can be done by attaching to the Microsoft CRM Asynchronous Service process (as opposed to the w3p.exe process when debugging plug-ins).

Thursday, 12 February 2009

Change default Public View using Plug-In

One of the things I get asked a lot about is having different Views on Entities for different users. This is possible using a Plug-In. I've attached a sample showing how to change defaults (and hide views) depending on the user's security role. The plug-in has to be registered for the RetreieveMultiple message on the savedquery entity to be be executed in the post stage (I have also included an export from the registration tool).

In this example I'm setting two different default views depending on whether the user is a Sales Person (My Active Contacts) or a Sales Manager (Active Contacts) and in addition, hiding a view if the user is a Sales Person.

Wednesday, 11 February 2009

Create a picklist attribute programmatically in CRM

I wrote a little console application that uses the CRM Metadata Service to create a Picklist attribute on the contact entity called country and adds all of the options to it. With a little modification, you can make it create any other picklist attributes..

I got a copy of the list of countries (ISO 3166) from here

I've attached the solution to my SkyDrive account, just remember to update the app.config file (fairly straightforward) and also add a reference to the CRM Metadata Web Service and name it MetadataSdk.



Happy coding!