Tuesday, December 28, 2010

CRM 4.0 Show Associated-View in an IFRAME

This was possible and was a help to almost all the developers. But after doing this some would need to hide the buttons(Add new and Add existing buttons) from the associated view.

For this i found a nice JS which was written in the below post. This was written for hiding one particular button, but i changed it to hide both button by calling the same functions. However all credit must go to the original poster as without that i wouldn't have got the idea to do this. Thanks mate.

http://social.microsoft.com/Forums/en/crmdevelopment/thread/1e8eeb04-947f-4cea-920d-4fa1946f633d


My Changed JS Snippet....



function HideAllViewButtons(Iframe) {
Iframe.onreadystatechange = function HideTitledButtons() {
if (Iframe.readyState == 'complete') {
var iFrame = frames[window.event.srcElement.id];
var liElements = iFrame.document.getElementsByTagName('li');

for (var i = 0; i < liElements.length; i++) {
if (liElements[i].getAttribute('title').indexOf('Add existing') != -1) {
liElements[i].style.display = 'none';
}
if (liElements[i].getAttribute('title').indexOf('Add a new') != -1) {
liElements[i].style.display = 'none';
}

}
}
}
}

Tuesday, December 14, 2010

Sunday, June 13, 2010

Form Assistance in CRM 4

In CRM 4 this feature is inbuilt to form customisation. When you open a CRM form through customization area in one of the tabs you have 2 check boxes.

one will be to add the form assistance to the CRM form but not expanded by default. the other one is to expand the form assistance by default.

if you need to expand the form assistance you have click this check box as well. but if you only wants to load it, but not expand it then you can leave the check box without ticking it and it wouldn't be expanded by default.

Monday, June 7, 2010

Publishing workflows.

When publishing workflows please check the scope of the workflow. It has 4 types.

• User – will only run for the user who has created the workflow
• BU – Will only run for the BU that the user is in
• Parent- Child - Will only run for the BU that the user is in and the parent BU
• Organization – will run for the whole organization.

Hiding the Date Part of a Date Time Field

Use the following javascript to do that.


document.getElementById("field_name").childNodes[0].childNodes[0].style.display = "none";
document.getElementById("field_name").childNodes[0].childNodes[1].style.display = "none";

Sunday, June 6, 2010

Disabling a time filed in CRM 4

If you need to disable the date field of the date time field and enable the time field you need to use the below java script to do so.

crmForm.all.Field_Name.Disabled = true;
crmForm.all.Field_Name.all.time.enable();


if you want to disable the time field only you need to use the below javascript.

crmForm.all.Field_Name.all.time.disable();

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...