Tuesday, April 06, 2010

Record Counter For Microsoft Dynamics CRM 4.0

Andriy Butenko demonstrates a code sample to display number of Records in current view in CRM 4.0 using a Plugin on CRM Team Blog. Click here for the code and article.

Friday, November 20, 2009

Enforcing Leaf Node Selection in Select Subject Dialogue Box

Alright... it's been a while, I was planning something major and had to stop blogging, anyways now I am back[Hopefully with a bang] and here is a first scriptlet on CRM.

Recently one of my colleague was facing an issue with Subject Lookup dialogue box. The requirement was to enable selection of only leaf-nodes i.e. any node with a child node should not be selected as a Subject. After little R&D I came up with the following

Edit : \CRMWeb\_controls\lookup\lookupsubject.aspx
In function applyChange
just below the following statement
if currentSubject != ""
{
put this script…
try{
if(document.getElementById(currentSubject.Id).parentNode.parentNode.attributes['isExpanded'])
{
alert('saaary.. saary meri vajah se hai..');
return;
}
}
catch(e)
{
alert('Error in sadu logic of leaf node selection.' + e.message);
}

I was in strange mood so I've put some garbage text in messages, basically first message box notifies end user when S/He tries to select a non-leaf node and the second message box says there was some error with the script.

Seriously, I love CRM and the endless possibilities of unsupported customizations. :) I hope you got the message ... to make it clear, this is unsupported customization and if you end up with a dead fish please DO NOT blame me.

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.

Monday, June 29, 2009

Adding a Custom Button to Advanced Find in CRM 4.0

Have you ever observed how powerful Advanced Find dialogue can be in the right hands? Well apart from looking at the customized result set and providing total control to filter the data Advanced Find can be used for some really cool tricks. Recently, I had to face a situation where I needed to turn Advanced Find into some bit simpler find by removing some functionalist and by adding a simple button on the Grid Toolbar.

I managed it somehow in few hours and thought to share it with you, just in case you also fall in the same trap some day. So here it goes, just note that, modifying Advanced Find is NOT at all supported and I DO NOT take any responsibility what so ever if you follow the steps I've mentioned below and end up with any kind of damage[mental\physical\financial\social\...].

Here are steps to add a button to advanced find window
1. Go to CRM Installation directory and navigate to \CRMWeb\AdvancedFind\. Mostly you will have to go to C:\Program Files\Microsoft Dynamics CRM\CRMWeb\AdvancedFind.
2. Take a back up of AdvFind.aspx.
3. Open AdvFind.aspx in any text editor. [Visual Studio is recommended though].
4. locate the first </form> tag.
5. Copy-paste the following line : <input type="button" onclick="Alert('Hey!!!... I am in Advanced Find Window...')" value="Click Me!!!" />
6. Save and Close the file.
7. Go to CRM and click on Advanced Find... Dialogue. You will see a long ugly button on top. Click on it to see the message.
This is a simple approach I've followed. There can be tons of things you can do. You can skin it to look like the real CRM buttons and then replace the alert message with some really useful and complex logic.

Anyways, I took it little further and added the following script and removed the button from the previous step.

<script language="javascript" type="text/javascript">
function DoIt() {
var template = document.getElementById("btnEditProperties");
var newNode = document.createElement(template.tagName);
newNode.setAttribute("class", "ms-crm-Menu");
newNode.setAttribute("tabIndex", "-1");
newNode.setAttribute("title", "Visit Metrix...");
var magic = "<SPAN class=ms-crm-Menu-Label><A class=ms-crm-Menu-Label tabIndex=-1 onclick='return false;' href='javascript:onclick();' target=_self><IMG class=ms-crm-Menu-ButtonFirst tabIndex=-1 alt='Visit Metrix....' src='/_imgs/vieweditor/16_viewProps.gif'><SPAN class=ms-crm-MenuItem-TextRTL tabIndex=0>http:\\\\
metrix.blogspot.com</SPAN></A></SPAN>";
newNode.insertAdjacentHTML("afterBegin", magic);
template.parentNode.appendChild(newNode);
}
DoIt();
</script>

and I got this :

Also you might want to add a little delay in the execution of the script by using window.setTimeout method otherwise it will give error in case the grid is not loaded by the time script is called.

Monday, June 22, 2009

Hide Elements on OnLoad in CRM 4.0/CRM 3.0

I know it is pretty simple to do but I see there are posts popping up here and there for the same. So here it is, a very simple script to hide form elements in CRM during page load. You can call the function from any where any time once you have put it on OnLoad event of the page.

document.HideElement = function(elementId) {
if (document.getElementById(elementId))
document.getElementById(elementId).style.display = 'none';
}

And here how you can use this function to hide various elements when CRM form loads

document.HideElement("_MBcrmFormSave"); // Hides Save button
document.HideElement("_MBcrmFormSaveAndClose"); // Hides Save And Close button

to hide an element say for example : AccountValue, following will be the code snippet

document.HideElement("skynet_AccountValue_c");
document.HideElement("skynet_AccountValue_d");
document.HideElement("skynet_AccountValue");

Wednesday, June 17, 2009

Will The Real GAC Folder Structure Please Show Up?

Just in case the above mentioned blogpost is gone, here is the command to 'mount' GAC as a drive.
subst x: "c:\windows\assembly\gac"
It solves the universal problem for the developers who wants to dissemble .net assemblies which are registered in GAC. Enjoy!!!

Tuesday, June 16, 2009

Disable Page Close Confirmation in CRM 4.0

If you have worked with CRM, then you must have observed an annoying popup message whenever you try to close a form once you have made any changes to it. In certain cases, you might like to avoid showing that dialogue. In one of the recent engagements, I had to change some values on the form when it loads but then users started complaining that even if they don't change anything they are presented with the dialogue box asking to save the record. And then what I had to put a crmForm.Save(); statement after I've changed the values[That's lame I know...]. However, I stumbled upon on this unsupported and undocumented function that helps you get rid of that irritating popup. Use it wisely and you will be good to go :

crmForm.detachCloseAlert()