Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Monday, December 15, 2008

How to delete records from CRM web forms using javascript in MS CRM 4.0

function DeleteEntityRecord(entityName, attributes, orgName)
{
      //attributes = #accountid> 92384923 #/accountid>#firstname>harry#/firstname> ...
  var xmlString = "#?sXml version='1.0' encoding='utf-8'?>";
      xmlString +="#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'>";
      xmlString +="#soap:Header>#CrmAuthenticationToken xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>";
      xmlString +="#AuthenticationType xmlns='http://schemas.microsoft.com/crm/2007/CoreTypes'>0#/AuthenticationType>";
      xmlString +="#OrganizationName xmlns='http://schemas.microsoft.com/crm/2007/CoreTypes'>" + orgName + "#/OrganizationName>";
      xmlString +="#CallerId xmlns='http://schemas.microsoft.com/crm/2007/CoreTypes'>00000000-0000-0000-0000-000000000000#/CallerId>";
      xmlString +="#/CrmAuthenticationToken>";
      xmlString +="#/soap:Header>";
      xmlString += " #soap:Body>" +
      xmlString +="   #Delete xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>";
      xmlString +="     #entity xsi:type='" + entityName + "'>";
      xmlString +=  attributes;
      xmlString +="     #/entity>";
      xmlString +="   #/Delete>";
      xmlString +=" #/soap:Body>";
      xmlString +="#/soap:Envelope>";


      oXmlHttp.open("POST", "http://localhost/mscrmservices/2007/crmservice.asmx",false);
      oXmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
      oXmlHttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Delete");
      oXmlHttp.send(sXml);
      
  var results = xmlHttpRequest.responseXML;
}

Please replace '#' with '<' after copying and before pasting..:)

How to avoid Mouse 'Right Click' Paste feature


function Disable_RightClick()
{
    if(event.button == 2)
    { 
        window.clipboardData.clearData();
        return false;
    }
}

crmForm.all.firstname.attachEvent("onmousedown",Disable_RightClick);

Friday, December 12, 2008

How to dynamically create querystring for a webform call..

I face this problem of making calls to web application and generating dynamic content based on the record selected by the user in CRM.

I created a button on the form. I had a constant url for the web form. I had to extract the qurystring value from the form data values. But special characters and
few manipulation is allowed in the isv.config file. So I created javascript methods in the 'onload' event method of form. 

In isv.config file:
Added Button to the Entity
added "JavaScript="SearchDetails();" attribute of the Button  

function SearchDetails()
{
.. implentation here
.. built dynamic url and made call to web application
}