El del CRM

The adventures of a Dynamics CRM geek

El del CRM

How to get a re-open activity button on Dynamics CRM 4.0

Wednesday, August 13 2008 by admin - Blog - No Comments

I’ve been working with Dynamics CRM for many moons, but I´m still being surprised by it from time to time. To be honest, I have to admit that is a practically endless product where you can have as many extension/customization opportunities as your imagination can produce. In fact, as some of my co-workers know, when someone asks me about if this or that is possible in Microsoft Dynamics CRM my answer is yes almost all the times [ I don’t remember a no right now, but just in case :o) ] the problem is find the way of doing it.

However, sometimes the surprises are not so good when you discover that some functionality that you almost were sure that it should be there it’s not there. It happened to me long time ago with the activities. As you already know all the crm entities has several states, usually active and inactive, and the activities are not an exception. Moreover, is possible to change the status of a record through the User Interface for almost of all of them. The surprise comes when you came across of customer requirement to be able to re-open closed activities and you thought “Ahh, easy… that´s already there”, but later you realize that there is not such option to do that on the UI.

The good news are that as usual all can be solved on Microsoft Dynamics CRM [as far as I remember now :o) ] . So, if we take a look to the CRM´s SDK we will realize that there are several messages to change estates for the entities programmatically, among them there is one for each type of activity. Having this ability, and adding some of the good old friend JavaScript to call Web Services along with the handy ISV.config files to the mix we will quickly get a solution for the problem.

Below is the JavaScript code that re-opens a closed Phone Call already embedded in a button definition. This piece is ready to be added to our ISV.config to get a brand new re-open activity button. If you want to use it with another activity type you just need to change "phonecall" for the schema name of the other activity type on the code i.e. "task".

  1: <Entity name="phonecall"> 
  2: <ToolBar ValidForCreate="0" ValidForUpdate="1"> 
  3: <Button Icon="/_imgs/ico_16_exportCustomizations.gif" JavaScript=" if(crmForm.FormType==4){ var xml = &apos;&apos; + &apos;&lt;?xml version=\&apos;1.0\&apos; encoding=\&apos;utf-8\&apos;?&gt;&apos; + &apos;&lt;soap:Envelope xmlns:soap=\&apos;http://schemas.xmlsoap.org/soap/envelope/\&apos; xmlns:xsi=\&apos;http://www.w3.org/2001/XMLSchema-instance\&apos; xmlns:xsd=\&apos;http://www.w3.org/2001/XMLSchema\&apos;&gt;&apos; + GenerateAuthenticationHeader() + &apos; &lt;soap:Body&gt;&apos; + &apos; &lt;Execute xmlns=\&apos;http://schemas.microsoft.com/crm/2007/WebServices\&apos;&gt;&apos; + &apos; &lt;Request xsi:type=\&apos;SetStatePhoneCallRequest\&apos;&gt;&apos; + &apos; &lt;EntityId&gt;&apos;+crmForm.ObjectId+&apos;&lt;/EntityId&gt;&apos; + &apos; &lt;PhoneCallState&gt;Open&lt;/PhoneCallState&gt;&apos; + &apos; &lt;PhoneCallStatus&gt;-1&lt;/PhoneCallStatus&gt;&apos; + &apos; &lt;/Request&gt;&apos; + &apos; &lt;/Execute&gt;&apos; + &apos; &lt;/soap:Body&gt;&apos; + &apos;&lt;/soap:Envelope&gt;&apos; + &apos;&apos;; var xmlHttpRequest = new ActiveXObject(&apos;Msxml2.XMLHTTP&apos;); xmlHttpRequest.Open(&apos;POST&apos;,&apos;/mscrmservices/2007/CrmService.asmx&apos;, false); xmlHttpRequest.setRequestHeader(&apos;SOAPAction&apos;,&apos;http://schemas.microsoft.com/crm/2007/WebServices/Execute&apos;); xmlHttpRequest.setRequestHeader(&apos;Content-Type&apos;, &apos;text/xml; charset=utf-8&apos;); xmlHttpRequest.setRequestHeader(&apos;Content-Length&apos;, xml.length); xmlHttpRequest.send(xml); var resultXml = xmlHttpRequest.responseXML; window.location.reload();}"> 
  4: <Titles> 
  5: <Title LCID="1033" Text="Re-Open Activity" /> 
  6: </Titles> 
  7: <ToolTips> 
  8: <ToolTip LCID="1033" Text="Re-Opens the activity if it is closed." /> 
  9: </ToolTips> 
  10: </Button> 
  11: </ToolBar> 
  12: </Entity> 

On next posts I will try to give some more details on how to complete this functionality by hiding this button when the activity is not closed, as well as some hints on formatting the JavaScript for the ISV.config file.

Regards,

Marco

PS: I've also attached a full isv.config file ready to be imported and tested on a dev environment.

kick it on DynamicsCrmKicks.com

customizations.zip (1.32 kb)

Tagged as: , , ,

Trackback URL to this Post http://marcoamoedo.com/trackback.ashx?id=16

Sorry comments are closed for this post

There are no trackbacks .