Sunday, July 19, 2009

CRM 4.0 Hide the date part of a DateTime field

So this is pretty easy but rare to face scenario. If you check DateTime field's format options, it says Date Only and Date And Time. But what if I want to have Time Only? This is what some one asked recently, and I thought, let me give this one a try. Again, unsupported and all that blah blah blah goes here, just get over with it and get to the good part.

function HidDatePart(targetFieldName)
{
crmForm.all[targetFieldName]DataValue = new Date();
document.getElementById(targetFieldName).childNodes[0].childNodes[0].style.display = "none";
document.getElementById(targetFieldName).childNodes[0].childNodes[1].style.display = "none";
}

just pass the targetFieldName parameter and you are good to go.

Remember you can't remove the date field using DOM operation, as it will start giving you errors.. Also by default time field is disabled, to enable it, it is necessary to add some value in Date Field.

Let me know if you need more help with this.

Removing Activities after entity has been created in CRM 4.0

Recently, I've started working on CRM bit seriously. Basically, my areas of interest includes .Net and DHTML and lot many other technologies. But CRM was never there in my list till last January. After taking a long break [Trust me anything beyond few hours away from computers, is LONG for me], in January, I realized, that I needed to give it a shot and since then the journey has been AWESOME!!! And here one of the problem I solved recently while helping out someone. If you have worked with CRM, you know how it makes your life really interesting some times. Like you can not disable the relationship between a custom made entity and notes/activities once you have created it. I am damn sure, it was some pressing dead line or/and regression testing would have shown some strange behavior on removal of the same so dev team might have decided to lock it permanently once it is created. And as usual sometimes you might wanna get rid of Activities from your custom relationship as a result of design change or maybe just for a challenge... in that case... here is a hack that might come handy. Only limitation is you will have to delete the entity and then recreate it after a few changes in the customization xml. So if you have any existing data, this is not what you should be doing[You should be looking for the guy or gal who designed your solution right?].

Standard ToCs applies and... yes.. you get me right... if something goes wrong I DO NOT Take any responsibility of any kind of damage that might occur due to this little hack.

Here is what I did to remove activities from my custom entity.
- Export the customization.
- Extract and open the customization xml.
- Open the xml file in Visual Studio or any other xml/text editor of your choice.
- Change
<HasRelatedActivities>True</HasRelatedActivities>
to
<HasRelatedActivities>False</HasRelatedActivities>
- Remove
<EntityMask>ActivityPointer</EntityMask>
- Remove ActivityPointerRegardingName from <DisplayMaskElement>
- Remove following <EntityRelationship> elements.
- _ActivityPointers
- _Appointments
- _Emails
- _Faxes
- _Letters
- _PhoneCalls
- _ServiceAppointments
- _Tasks

- Save the xml file.
- Import and publish the customization xml file.

Let me know how it goes, as I would love to hear whether it worked for you or not.