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 = "/mscrmservices/2006";
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
//alert(serverUrl+ "/crmservice.asmx");
xmlhttp.open("POST", serverUrl + "/crmservice.asmx", false);
xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8")
xmlhttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2006/WebServices/Execute")
xmlhttp.send("<?xml version=’1.0′ encoding=’utf-8′?>"+"\n\n"+"<soap:Envelope"+
‘ xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"‘+
‘ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"‘+
‘ xmlns:xsd="http://www.w3.org/2001/XMLSchema">‘+
‘ <soap:Body>‘ +
‘ <Request xsi:type="SetStateAppointmentRequest"‘+
‘ xmlns="http://schemas.microsoft.com/crm/2006/WebServices"> ‘+
‘ <EntityId>‘ + activityid + ‘</EntityId>‘+
‘ <AppointmentState>Open</AppointmentState>‘+
‘ <AppointmentStatus>1</AppointmentStatus>‘+
‘ </Request>‘+
‘ </soap:Body>‘+
‘ </soap:Envelope>‘)
var result = xmlhttp.responseXML.xml;
if (result.indexOf(‘faultcode’) < 0) {
window.open(‘/CRMReports/viewer/drillopen.aspx?ID=’ + activityid + ‘&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 “"”, “<” and “> “.
Therefore the following text: <AppointmentState>Open</AppointmentState> has to be encoded as
<AppointmentState>Open</AppointmentState> .
2.) Calling CRM web service using JScript.
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”.
I hope that this sample brings additional productivity to you and your users with the best CRM software I know.