Archive

Archive for the ‘CRM’ Category

Copying a Microsoft CRM Workflow

December 13, 2010 Leave a comment

To copy a CRM Workflow, first turn it into a Template then create a new workflow using the template.

Link below is a simple explanation of it":

Copying a Microsoft CRM Workflow – C5 Insight Microsoft CRM Blog > Home

Categories: CRM

Using FetchXML in CRM javascript

December 13, 2010 1 comment

Setup Form for JavaScript Development

During development I like to update the CRM Form is call a .js file. This allows me to make changes to the code without having to publish the entity again and again.

I add the following to the code:

/***   USE ONLY FOR DEVELOPMENT:: SUPPORTS EXTERNAL JS SCRIPT

var head = document.getElementsByTagName(‘head’)[0];
var script = document.createElement(‘script’);
script.type= ‘text/javascript’;
script.src= ‘/ISV/nameOfTheJSFile.js?noCache=’ +  Math.random();
script.onreadystatechange= function () {
if (this.readyState == ‘complete’ || this.readyState == ‘loaded’)
{
document.OnLoadCode()
}
}
head.appendChild(script);

  USE ONLY FOR DEVELOPMENT:: SUPPORTS EXTERNAL JS SCRIPT ***/

I then add fetchXML scripts:

/**********
/********************************************************************/
function CreateXmlHttpObject() //CreateXmlHttp 

var oXmlHttp = null; 
if(window.XMLHttpRequest) 

  oXmlHttp = new XMLHttpRequest(); 

else 

  var arrProgIds = ["Msxml2.XMLHTTP","Microsoft.XMLHTTP"]; 
  for(var iCount = 0; iCount < arrProgIds.length;iCount++) 
  { 
   try 
   { 
    oXmlHttp = new ActiveXObject(arrProgIds[iCount]); 
    break; 
   } 
   catch(e){} 
  } 

  
return oXmlHttp; 

/**********************************************************************/
function FetchEncode( strInput ) //_HtmlEncode 

var c; 
var HtmlEncode = ”; 
 
if(strInput == null) 

  return null; 

if (strInput == ”) 

  return ”; 

 
for(var cnt = 0; cnt < strInput.length; cnt++) 

  c = strInput.charCodeAt(cnt); 
 
  if (( ( c > 96 ) && ( c < 123 ) ) || 
  ( ( c > 64 ) && ( c < 91 ) ) || 
  ( c == 32 ) || 
  ( ( c > 47 ) && ( c < 58 ) ) || 
  ( c == 46 ) || 
  ( c == 44 ) || 
  ( c == 45 ) || 
  ( c == 95 )) 
  { 
   HtmlEncode = HtmlEncode + String.fromCharCode(c); 
  } 
  else  
  { 
   HtmlEncode = HtmlEncode + ‘&#’ + c + ‘;’; 
  } 

  
return HtmlEncode; 
}

formatCurrency = function(num)
{
    num = num.toString().replace(/\$|\,/g,”);
    if(isNaN(num))
    {    num = "0";
    }
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
    cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    {
        num = num.substring(0,num.length-(4*i+3))+’,’+    num.substring(num.length-(4*i+3));
    }
    return (((sign)?”:’-‘) + ‘$’ + num + ‘.’ + cents);
}

/************************************************************************/
function Fetch( xml ) 
{  
var Xml = "<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\">" 
  Xml += GenerateAuthenticationHeader() 
  Xml += "<soap:Body>"; 
  Xml += "<Fetch xmlns=\"
http://schemas.microsoft.com/crm/2007/WebServices\">"; 
  Xml += "<fetchXml>"; 
  Xml += FetchEncode(xml);
  Xml += "</fetchXml>"; 
  Xml += "</Fetch>"; 
  Xml += "</soap:Body>"; 
  Xml += "</soap:Envelope>"; 
 
var XmlHttp = CreateXmlHttpObject(); // Microsot CreateXmlHttp function 
  XmlHttp.open("POST", "/mscrmservices/2007/crmservice.asmx", false ); //Sync Request 
  XmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); 
  XmlHttp.setRequestHeader("SOAPAction", "
http://schemas.microsoft.com/crm/2007/WebServices/Fetch"); 
  XmlHttp.send(Xml); 
 
var XmlDoc = new ActiveXObject("Msxml2.DOMDocument"); 
  XmlDoc.async = false; 
  XmlDoc.resolveExternals = false; 

  XmlDoc.loadXML(XmlHttp.responseXML.text); 
 
return XmlDoc; 
}
 

 

This will allow FetchXMLBuilder to work easily. Below is an example:

 

GetCategory = function(projectbudgetdetailid)
{
    try{
        var _xml = ‘FETCHXML‘;
        var FetchResult = Fetch(_xml);                 
        SetCostCategory(FetchResult.selectSingleNode("//costcategoryid").text,FetchResult.selectSingleNode("//name").text);            
        return;
    }
    catch(er)
    {
        alert("ERROR when calling GetCategory: " + er.message);
    }

}

Categories: CRM Tags: