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"> toolbar> entity>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: CRM, customizations