How to reopen and make changes to a closed appointment


In another of our guest blog series, Jürgen Beck provides a developer's view demonstrating out customizable Microsoft Dynamics CRM 3.0 is.


There are some good reasons why an appointment is read-only after closing it. But sometimes it could be necessary to make additional changes. With the following JScript-based solution you will get a button in the toolbar of the appointment form to reopen a closed appointment.


Copy the following lines to an appropriate position of the isv.config.xml of your Microsoft CRM setup. You can find more information how to do this in the Microsoft CRM SDK (Customizing Using ISV.Config): http://msdn2.microsoft.com/en-us/library/aa681363.aspx.

    <Entity name="appointment">


      <ToolBar ValidForCreate="0" ValidForUpdate="1">


        <Button Title="Reopen appointment" ToolTip="Reopen this appointment if this appointment is closed already and you have additional changes." Icon="/_imgs/ico_18_debug.gif" JavaScript="


var activityid = crmForm.ObjectId;


var serverUrl = &quot;/mscrmservices/2006&quot;;


var xmlhttp = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);


//alert(serverUrl+ &quot;/crmservice.asmx&quot;);


xmlhttp.open(&quot;POST&quot;, serverUrl + &quot;/crmservice.asmx&quot;, false);


xmlhttp.setRequestHeader(&quot;Content-Type&quot;, &quot;text/xml; charset=utf-8&quot;)


xmlhttp.setRequestHeader(&quot;SOAPAction&quot;, &quot;http://schemas.microsoft.com/crm/2006/WebServices/Execute&quot;)


xmlhttp.send(&quot;&lt;?xml version='1.0' encoding='utf-8'?&gt;&quot;+&quot;\n\n&quot;+&quot;&lt;soap:Envelope&quot;+


' xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;'+


' xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;'+


' xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;'+


' &lt;soap:Body&gt;' +


' &lt;Request xsi:type=&quot;SetStateAppointmentRequest&quot;'+


' xmlns=&quot;http://schemas.microsoft.com/crm/2006/WebServices&quot;&gt; '+


' &lt;EntityId&gt;' + activityid + '&lt;/EntityId&gt;'+


' &lt;AppointmentState&gt;Open&lt;/AppointmentState&gt;'+


' &lt;AppointmentStatus&gt;1&lt;/AppointmentStatus&gt;'+


' &lt;/Request&gt;'+


' &lt;/soap:Body&gt;'+


' &lt;/soap:Envelope&gt;')


var result = xmlhttp.responseXML.xml;


if (result.indexOf('faultcode') &lt; 0) {


 window.open('/CRMReports/viewer/drillopen.aspx?ID=' + activityid + '&amp;OTC=4201');


} else {


 alert(result);


}


 


" Client="Web" />


      </ToolBar>


    </Entity>


Maybe there are some new procedures for you in this sample.

1.) The use of JScript in isv.config.xml


With the JavaScript-attribute of the Button-element you can define JScript which is executed when a user clicks on the button. If you wonder why some characters looks scrambled just remember, that the isc.config.xml is a xml file and therefore some characters (", < and >) have a special meaning and have to be encoded as “&quot;”, “&lt;” and “&gt; “.


Therefore the following text: <AppointmentState>Open</AppointmentState> has to be encoded as
&lt;AppointmentState&gt;Open&lt;/AppointmentState&gt; .

2.) Calling CRM web service using JScript.


You can find more information about this in the Microsoft CRM Team Blog entry of Arash Ghanaie-Sichanie: http://blogs.msdn.com/arash/archive/2006/08/29/729320.aspx


3.) Changing the state of an appointment.


This is no rocket science because there is a method “SetStateAppointmentRequest” for this in the Microsoft CRM web service. With this method you can set the state of an appointment to “Open” again. Don’t forget also to set the State Reason to an appropriate value. In this case AppointmentState is set to “Open” and AppointmentStatus is set to “1”.


You can find more information how to use this kind of method here: http://msdn2.microsoft.com/en-us/library/aa684073.aspx

If you want to you can also modify this sample to reopen other activities or for other interesting things. Just have a look here for all methods of Microsoft CRM: http://msdn2.microsoft.com/en-us/library/aa683649.aspx

I hope that this sample brings additional productivity to you and your users with the best CRM software I know.

Best regards,

Jürgen Beck
MVP for Microsoft Dynamics CRM
Certified Developer for Microsoft Dynamics CRM

Comments (2)

  1. Andrew says:

    Good artical, previously we code through SQL. Now we change it to this one, Thanks

  2. peter says:

    good job, does this customization also work offline?

Skip to main content