miércoles, 21 de diciembre de 2011

Convertir campo de texto en un picklist

Esta función esta pensada en que puedas guardar los valores en un campo de texto, a partir de un picklist llenado dinamicamente con un webservice.

Lo que se hace es convertir el campo de texto en un picklist, luego lo llenas con el webservice y cuando se guarde el formulario se salvaran los datos en el campo de texto.

function ConvertTextToPickList( controlId )

{

var textControl = document.getElementById( controlId );
var picklistControl = document.createElement( "SELECT" );
picklistControl.id = textControl.id;
picklistControl.req = textControl.req;
picklistControl.className = "ms-crm-selectBox ";
picklistControl.value = textControl.DataValue;
textControl.parentElement.appendChild( picklistControl );
textControl.parentElement.removeChild( textControl );
return picklistControl ;

}



jueves, 1 de diciembre de 2011

xmlhttp request CRM, for a webservice Method.

function xmlCall(url)
{
alert('xmlCall ini ' + url );
   var xmlDoc;
   var xmlhttp;
  
    if (window.XMLHttpRequest)
    {
alert('XMLHttpRequest ini ' + url );
        xmlhttp=new XMLHttpRequest();
alert('XMLHttpRequest after'  );
    }
    else
    {
alert('Else XMLHttpRequest'  );
        try
        {
            xmlhttp=new ActiveXObject("MSXML2.ServerXMLHTTP");
        }
        catch (e) {}
        try
        {
            xmlhttp=new ActiveXObject("MSXML2.XMLHTTP.6.0");
        }
        catch (e) {}
        try
        {
            xmlhttp=new ActiveXObject("MSXML2.XMLHTTP.3.0");
        }
        catch (e) {}
        try
        {
            xmlhttp=new ActiveXObject("MSXML2.XMLHTTP");
        }
        catch (e) {}
        try
        {
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e) {}
        throw new Error("This browser does not support XMLHttpRequest.");
    }
alert('xmlhttp.open ini');
    xmlhttp.open("GET",url,false) ;
alert('xmlhttp.open after');
    try
    {
alert('xmlhttp.send ini');
        xmlhttp.send();
alert('xmlhttp.send after');
        var i = 0;
        var xmlDoc = xmlhttp.responseXML;
        for (i = 0; i < xmlDoc.getElementsByTagName('ROWID').length; i++) {
            alert('Id:' + xmlDoc.getElementsByTagName('ROWID')[i].firstChild.nodeValue);
            alert('descr:' + xmlDoc.getElementsByTagName('descr')[i].firstChild.nodeValue);
        }
    }
    catch (e) { alert('Error de lectura ' + e.message + 'en ' + url); };
    xmlDoc = xmlhttp.responseXml;
}
xmlCall( 'http://server/service.asmx/GetCountry');

How to load a .js File to Dynamics CRM


   function load_script (url) 
     { 
        var x = new ActiveXObject("Msxml2.XMLHTTP"); 
         x.open('GET', url, false); x.send(''); 
       eval(x.responseText); 
        var s = x.responseText.split(/\n/); 
         var r = /^function\s*([a-z_]+)/i; 
        for (var i = 0; i < s.length; i++) 
         { 
           var m = r.exec(s[i]); 
            if (m != null) 
                window[m[1]] = eval(m[1]); 
        } 
   } 
     
    load_script("/_customscript/jquery-1.2.6.min.js"); 
    load_script("/_customscript/jqModal.js"); 
    load_script("/_customscript/jqDnR.js"); 
    load_script("/_customscript/customscript.js");