Monday, July 12, 2010

Using RemoteCommand in CRM 4.0

What is it RemoteCommand ?
RemoteCommand is Microsoft XmlHttp interface.

Microsoft blocked the option to use RemoteCommand in CRM 4.0
How to use RemoteCommand in CRM 4.0?
1. Copies file RemoteCommand.JS from CRMWEB\_static\_controls\RemoteCommands to user local folder with JS and rename the file for instance customRemote.js
2. Rename function: RemoteCommand to CustomCommand and add another parameters for instance:
function CustomCommand (sObject, sCommand, sUrlBase, sNamespace)
3. Change the row:
var sCommandNamespace =_sWebServicesNamespace; to
var sCommandNamespace = sNamespace ? sNamespace : _sWebServicesNamespace;

finish to change the file.

Call to function from Javascript:

var cmd = new CustomCommand('webServiceName', 'functionName', '/MySite/', 'http://NameSpace');
cmd.SetParameter('incidentID', objectid);
cmd.SetParameter('targetID', instanceID);
var rslt = cmd.Execute();
if (!rslt || !rslt.ReturnValue){
//work good
return;

}
if (rslt.ReturnValue.errorDescription) {
//Failed
alert(rslt.ReturnValue.errorDescription);
return;
}

Define name space in c# code:

[WebService(Namespace="http://NameSpace")]
public class webServiceName: System.Web.Services.WebService {


thanks,
Rami Heleg,