Friday, April 2, 2010

Reading Excel 2007 Files with 64 Bit Enviornments

There are many issues in reading excel 2007 files using dotnet framework. This might work for 32 bit environment, but doesn't work for 64 bit environment.

If you want this to work you need to compile your project using *86 compilation.
You can do this by right clicking the project and choosing properties. Then a new window will appear with project details. Select the Build tab and from there you need select target CPU dropdown. There you need to select *86 platform.

This will probably be fixed by the dotnet team with a patch hopefully.

Getting the Querystring using Javascripts

The following javascript displays how to get a querystring value from a URL.

function RetreiveValues()
{
//Getting the URL part
var querystring = location.search.substring(1);
//Getting the string value
var objectTypeCode = getQuerystring('Flag');
}


function getQuerystring(key, default_)
{
if (default_ == null) default_ = "";
key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
var qs = regex.exec(window.location.href);
if (qs == null)
return default_;
else
return qs[1];
}

Thursday, April 1, 2010

Multi Purpose Workflow

Is it possible to write a workflow that can be triggered for many entities in CRM.
The answer is yes. You can do that.

Rather than writing several workflows to get this done you can write one workflow and then use a variable for flag here.

I have listed below a sample workflow.

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{

try
{
Guid ID1 = ((SDK.Lookup)base.GetValue(ID1Property)).Value;
string Type = ((String)base.GetValue(TypeProperty));
Guid _iID = Guid.Empty;

switch (Type)
{
case "1":
_iID = ((SDK.Lookup)base.GetValue(iIDProperty)).Value;
break;
case "2":
_iID = ((SDK.Lookup)base.GetValue(pIDProperty)).Value;
break;
case "3":
_iID = ((SDK.Lookup)base.GetValue(qIDProperty)).Value;
break;
case "4":
_iID = ((SDK.Lookup)base.GetValue(fIDProperty)).Value;
break;
}

IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
IWorkflowContext context = contextService.Context;

}
catch (Exception ex)
{
}


return ActivityExecutionStatus.Closed;
}


as for this example we need to create 4 dependency properties. they are
iIDProperty, pIDProperty, qIDProperty, fIDProperty.

depending on what we get for the switch statement the relevant dependency property would get updated.

CRM 4 N: N Plugin

It’s been a very long time since I have posted anything. I (and our team) have been very busy with a project going on. However there is couple of new things that I have found in CRM that I thought of sharing with you.

You might know this, you might not know this “We cannot write a plugin or a workflow for CRM N: N (many to many) relationship.” This might cause you a lot of issues and when a new record is added to such a relationship you might want to trigger some other event. We certainly came across that situation and tried everything to no avail. Then we found an unsupported customization which was published in Google by Aaron. That was very very helpful. I have pasted the link below.

http://consulting.ascentium.com/blog/crm/Post533.aspx

What we do here is enable both “Association” and “Disassociation” SDK message to the plugin registration tool. Also when enabling this, it would act as a generic plugin which would get fired for the entire N: N relationships in CRM. This is handy. I’m sure that with CRM 5, dynamics team would add this facility also. But for the time being we might have to live with this solution.

After registering the plugin the code needed to capture information is also pasted below. Whatever is here is an extended version of what was pasted in the above link. Thanks again to Aaron.




protected override void PostAssociateEntities(IPluginExecutionContext context)
{
TextWriter textWriter = TextWriter.Synchronized(File.AppendText(@"C:\Temp\PostAssociateEntities.txt"));
if (context.MessageName == "AssociateEntities")
{
if (context.InputParameters.Contains("Moniker1"))
{
Moniker EntityMoniker = (Moniker)context.InputParameters["Moniker1"];
Guid Moniker1 = EntityMoniker.Id;
string Name = EntityMoniker.Name;
textWriter.WriteLine(EntityMoniker.Id.ToString());
textWriter.WriteLine(EntityMoniker.Name.ToString());
}

if (context.InputParameters.Contains("Moniker2"))
{
Moniker EntityMoniker = (Moniker)context.InputParameters["Moniker2"];
textWriter.WriteLine(EntityMoniker.Id.ToString());
textWriter.WriteLine(EntityMoniker.Name.ToString());
}
textWriter.Close();

}

}

Retrieving Calendar of a Bookable Resource in Dynamics

There are occasions where we need to retrieve working days and working times of a resource in Dynamics grammatically. This is quite possible...