Dynamics CRM, Mobility and other stuff

dinsdag, december 27, 2005

Adding "Next/Previous" buttons to Entity Details Form

Update: I've updated the sample due to some feedback I received, read about it here! BTW, the download link at the bottom of this article also points to the updated sample!

Last week, I was looking through the history of a Contact in CRM, trying to locate a certain e-mail activity. So I opened the History tab and opened the first e-mail. Nope, not the one. Next.

After closing and opening 4 e-mails, I thought it would be nice to have some Previous/Next buttons, just like Outlook has when you open an e-mail. It's not very productive to keep opening and closing those popup windows.

So I came up with some javascript that does this for me. All you have to do is put this in your isv.config.xml:

< name="account">< validforcreate="0" validforupdate="1">< title="Previous" javascript="var _cwrRecordIndex; var _cwrGrid=window.opener.document.all['crmGrid'].InnerGrid; var _cwrRecords=_cwrGrid.AllRecords; for(var i=0; i<_cwrRecords.length; i++){if(_cwrRecords[i][0] == crmForm.ObjectId){if(i!=0){window.location.href=window.location.href.split('?')[0]+'?id='+_cwrRecords[i-1][0];_cwrGrid.UnselectRecords();_cwrGrid.SelectRecords(i-1,i-1,false);}}}" client="Web" icon="/_imgs/cwr_previous.gif">< title="Next" javascript="var _cwrRecordIndex; var _cwrGrid=window.opener.document.all['crmGrid'].InnerGrid; var _cwrRecords=_cwrGrid.AllRecords; for(var i=0; i<_cwrRecords.length; i++){if(_cwrRecords[i][0] == crmForm.ObjectId){if(i!=_cwrRecords.length-1){window.location.href=window.location.href.split('?')[0]+'?id='+_cwrRecords[i+1][0];_cwrGrid.UnselectRecords();_cwrGrid.SelectRecords(i+1,i+1,false);}}}" client="Web" icon="/_imgs/cwr_next.gif">

Note, it should go all on one line in your isv.config.xml. No line breaks.

Note 2: I put a space between the "<" and the element name, otherwise blogger thinks it's markup. I didn't really optimize the javascript code. Probably could be better, but this is the quick and dirty approach and I didn't feel like including a javascript file and then calling a function. All the code is inside the Javascript attribute. Also note that I use some undocumented javascript methods, so it's not supported! BTW, If you paid attention you would see that the code uses the entity "account". That's right. Unfortunately, CRM only permits you to customize the detail forms of certain entities, namely: account campaign campaignactivity campaignresponse incident (SDK wrongly calls this case) contact Custom entities invoice lead list opportunity salesorder quote You see? No activities! Anyway, for educational purposes I continue :). It does work for the other entities. So if you want to quickly browse through the invoices of an account, you can do that. Just add the two buttons to the invoice entity in your isv.config.xml. Here's a screenshot that shows browsing through accounts. Screenshot.

You can download a zip file which includes a sample isv.config.xml file and two images that you can put in the _imgs folder of your CRM webroot. Download it here.

Have fun!

Labels: ,

4 Comments:

  • I downloaded it and it works just fine!great idea...

    By Anonymous Ricardo - Portugal, at 4/4/06 18:31  

  • This is a great little customization and I use it all the time. Thanks! As a tip: If you want to use this on custom entities, you need to add the entity type code to the URL. If you open a custom entity in the web client, you will see at the end of the URL in the address bar something like "&etc=10001". To add this to the script in the isv.config.xml, you just modify the part that builds the URL. Here's an example (note that you need to use the code for the 'and' symbol which is the following without the spaces: & amp ; (blogger wants to convert this to just &)

    < Button Title="Previous" JavaScript="var _cwrRecordIndex; var _cwrGrid=window.opener.document.all['crmGrid'].InnerGrid; var _cwrRecords=_cwrGrid.AllRecords; for(var i=0; i<_cwrRecords.length; i++){if(_cwrRecords[i][0] == crmForm.ObjectId){if(i!=0){window.location.href=window.location.href.split('?')[0]+'?id='+_cwrRecords[i-1][0]+'&etc=10001';_cwrGrid.UnselectRecords();_cwrGrid.SelectRecords(i-1,i-1,false);}}}" Client="Web" Icon="/_imgs/cwr_previous.gif" / >

    By Blogger Matt Wittemann, at 16/1/07 16:04  

  • Matt's script can even be made a bit more deployment independent. Everybody who has been involved in deployment of customizations in CRM knows that entity type codes may be different for the same customization in different deployments, since the type codes are a deployment specific incrementing number (eg. new_timesheet may have a typecode of 10001 in your test environment, while it's 10004 in a production environment with your customer).
    The CRM team has addressed this issue in MS CRM 4. You can now use etn=new_timesheet (Entity Type Name) instead of etc=10001. This makes deployment of customizations quite a bit easier!

    Bart Vierbergen

    By Anonymous Anoniem, at 20/11/07 08:50  

  • Hi Jeffry,

    I tried this on CRM 4.0 but I am not able to upload the isv.config.xml file after adding the lines. Am I doing something wrong ?

    Jeroen de Hoog

    By Blogger Jeroen, at 19/2/08 16:11  

Een reactie plaatsen

Links to this post:

Een koppeling maken

<< Home