locked
CRM 4.0 Web service Endpoint Code needs converting to CRM2013 RRS feed

  • Question

  • We initially had a company look after our CRM this company has now gone bust and we have been left to look after the system we curently have the below code left that is preventing the upgrade to CRM 2013 because of its referencing to the 2007 WebService Endpoint, unfortunately i do not know the first thing in coding this correcly and wondered if there was a conversion tool like the Javacript Tool on CodePlex??

    function Form_onload()
    {
    if (Xrm.Page.getAttribute("transactioncurrencyid").getValue() != null) {
      Xrm.Page.getControl("transactioncurrencyid").setDisabled(true);
      Xrm.Page.getAttribute("transactioncurrencyid").setSubmitMode("always");
    }

    var sbl_data = new Object();
    sbl_data.org_price = 0.0;
    window.sbl_data = sbl_data;

    if (Xrm.Page.getAttribute("transactioncurrencyid").getValue() != null) {
      Xrm.Page.getAttribute("new_unitbuyprice").fireOnChange();
    }

    Xrm.Page.getAttribute("new_marginpct").setSubmitMode("always");
    Xrm.Page.getAttribute("new_linetotal").setSubmitMode("always");
    Xrm.Page.getAttribute("new_totalmargin").setSubmitMode("always");
    Xrm.Page.getAttribute("new_alternativepart").setSubmitMode("always");
    Xrm.Page.getAttribute("new_distributorid").setSubmitMode("always");
    Xrm.Page.getAttribute("new_vendorird").fireOnChange();
    Xrm.Page.getAttribute("new_writeinproduct").fireOnChange();
    }
    function new_agreementtype_onchange()
    {
    Xrm.Page.getAttribute("new_vendorird").fireOnChange();
    }
    function new_quantity_onchange()
    {
    Xrm.Page.getAttribute("new_unitsellprice").fireOnChange();
    }
    function new_vendorird_onchange()
    {
    var condv = '';
    var conda = '';
    var sbl_vend = "";

    if (&& (Xrm.Page.getAttribute("new_vendorird").getValue() != null) {
      sbl_vend = Xrm.Page.getAttribute("new_vendorird").getValue()[0].name;
      condv = '<condition attribute="new_vendorid" operator="eq" value="'+Xrm.Page.getAttribute("new_vendorird").getValue()[0].id+'" />';

    var xml = "";
    xml += "<?xml version='1.0' encoding='utf-8' ?>";
    xml += "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'";
    xml += " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'";
    xml += " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>";
    xml += window.opener.Xrm.Page.context.getAuthenticationHeader();
    xml += "<soap:Body>";
    xml += "<Fetch xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>";
    xml += "<fetchXml>";

    var fetchxml = "<fetch mapping='logical'><entity name='new_vendor'>";
    fetchxml += "<attribute name='new_distrbutorid'/><filter type='and'>"
    fetchxml += "<condition attribute='new_vendorid' operator='eq' value='";
    fetchxml +=  Xrm.Page.getAttribute("new_vendorird").getValue()[0].id+ "'/>";
    fetchxml += "</filter></entity></fetch>";

    fetchxml = fetchxml.replace(/</g,'&lt;');
    fetchxml = fetchxml.replace(/>/g,'&gt;');

    xml += fetchxml;

    xml += "</fetchXml></Fetch></soap:Body></soap:Envelope>";

    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Fetch");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
    xmlHttpRequest.send(xml);

    var resultXml = xmlHttpRequest.responseXML;
    var fetchresult = resultXml.xml;

    var lookup = new Object();
    lookup.entityType = 'account';

    fetchresult = fetchresult.replace(/&lt;/g,'<');
    fetchresult = fetchresult.replace(/&gt;/g,'>');

    var oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    oXmlDoc.async = false; 
    oXmlDoc.loadXML(fetchresult);

    var results = oXmlDoc.getElementsByTagName('result');
    for (i=0;i < results.length;i++) {
      var disti= results[i].selectSingleNode('./new_distrbutorid');
      if (disti != null) {
        lookup.name = disti.attributes.getNamedItem('name').text;
        lookup.id = disti.nodeTypedValue;
      }
    }
     Xrm.Page.getAttribute("new_distributorid").setValue([lookup]);

    }

    if (sbl_vend == "Other") {
      Xrm.Page.getControl("new_vendortext").setDisabled(false);
      Xrm.Page.getControl("new_vendortext").setVisibility(true);
      Xrm.Page.getControl("new_vendortext_c").setVisibility(true);
      Xrm.Page.getAttribute("new_vendortext").setRequiredLevel('required');
      Xrm.Page.getControl("new_distributorid").setDisabled(false);
    }
    else {
      Xrm.Page.getAttribute("new_vendortext").setRequiredLevel('none');
      Xrm.Page.getControl("new_vendortext").setDisabled(true);
      Xrm.Page.getControl("new_vendortext").setVisibility(false);
      Xrm.Page.getControl("new_vendortext_c").setVisibility(false);
      Xrm.Page.getControl("new_distributorid").setDisabled(true);
    }

    if (Xrm.Page.getAttribute("new_agreementtype").getValue() != null) {
      agletter = Xrm.Page.getAttribute("new_agreementtype").getSelectedOption().text.substring(0,1);
      conda = '<condition attribute="new_agreementtypes" operator="like" value="%'+agletter+'%" />';
    }

    crmForm.all.new_productid.AddParam('filters', '<filters><filter entity="new_pricelistproduct">'+condv+conda+'</filter></filters>');
    }
    function new_unitsellprice_onchange()
    {
    var sbl_qty = 0;
    var sbl_sell = 0.0;
    var sbl_buy = 0.0;

    if (Xrm.Page.getAttribute("new_quantity").getValue() != null) {
      sbl_qty = Xrm.Page.getAttribute("new_quantity").getValue();
    }
    if (Xrm.Page.getAttribute("new_unitsellprice").getValue() != null) {
      sbl_sell = Xrm.Page.getAttribute("new_unitsellprice").getValue();
    }
    if (Xrm.Page.getAttribute("new_unitbuyprice").getValue() != null){
      sbl_buy= Xrm.Page.getAttribute("new_unitbuyprice").getValue();
    }
    Xrm.Page.getAttribute("new_linetotal").setValue((sbl_qty * sbl_sell));
    Xrm.Page.getAttribute("new_totalmargin").setValue(((sbl_sell - sbl_buy) * sbl_qty));

    var sbl_pct = (((sbl_sell - sbl_buy) / sbl_sell) * 100.0);
    if (isNaN(sbl_pct)) sbl_pct = 0.0;
    if (sbl_pct <= 0.0) sbl_pct = 0.0;
    if (sbl_pct >= 100.0) sbl_pct = 100.0;
    Xrm.Page.getAttribute("new_marginpct").setValue(sbl_pct);
    }
    function new_unitbuyprice_onchange()
    {
    var sbl_reqd = false;
    var sbl_reqNew = 'none';
    if (Xrm.Page.getAttribute("new_writeinproduct").getValue() == false) {
      if (Xrm.Page.getAttribute("new_unitbuyprice").getValue() < window.sbl_data.org_price) {
        if (window.sbl_data.org_price != 0.0) {
          sbl_reqd = true;
     sbl_reqNew = 'required';
        }
      }
    }

    if (Xrm.Page.ui.getFormType() == 1) {
      Xrm.Page.getAttribute("new_pricereductionreason").setValue(null);
    }
    Xrm.Page.getControl("new_pricereductionreason").setDisabled(!sbl_reqd);
    Xrm.Page.getAttribute("new_pricereductionreason").setRequiredLevel(sbl_reqNew);
    Xrm.Page.getAttribute("new_quantity").fireOnChange();
    }
    function new_productid_onchange()
    {
    Xrm.Page.getAttribute("new_partno").setValue(null);
    Xrm.Page.getAttribute("new_unitbuyprice").setValue(null);

    if (Xrm.Page.getAttribute("new_productid").getValue() != null) {
    var sbl_productid = Xrm.Page.getAttribute("new_productid").getValue()[0].id;

    Xrm.Page.getControl("new_unitbuyprice").setDisabled(false);
    Xrm.Page.getControl("new_unitsellprice").setDisabled(false);
    Xrm.Page.getControl("new_quantity").setDisabled(false);

    var xml = "";
    xml += "<?xml version='1.0' encoding='utf-8' ?>";
    xml += "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'";
    xml += " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'";
    xml += " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>";
    xml += window.opener.Xrm.Page.context.getAuthenticationHeader();
    xml += "<soap:Body>";
    xml += "<Fetch xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>";
    xml += "<fetchXml>";

    var fetchxml = "<fetch mapping='logical'><entity name='new_pricelistproduct'>";
    fetchxml += "<attribute name='new_description'/>";
    fetchxml += "<attribute name='new_sblbuy'/>";
    fetchxml += "<filter type='and'>"
    fetchxml += "<condition attribute='new_pricelistproductid' operator='eq' value='";
    fetchxml += sbl_productid + "'/>";
    fetchxml += "</filter></entity></fetch>";

    fetchxml = fetchxml.replace(/</g,'&lt;');
    fetchxml = fetchxml.replace(/>/g,'&gt;');

    xml += fetchxml;

    xml += "</fetchXml></Fetch></soap:Body></soap:Envelope>";

    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Fetch");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
    xmlHttpRequest.send(xml);

    var resultXml = xmlHttpRequest.responseXML;
    var fetchresult = resultXml.xml;

    fetchresult = fetchresult.replace(/&lt;/g,'<');
    fetchresult = fetchresult.replace(/&gt;/g,'>');

    var oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    oXmlDoc.async = false; 
    oXmlDoc.loadXML(fetchresult);

    var results = oXmlDoc.getElementsByTagName('result');
    for (i=0;i < results.length;i++) {
      var description = results[i].selectSingleNode('./new_description');
      if (description != null) {
        Xrm.Page.getAttribute("new_partno").setValue(description.text.replace('&amp);','&');
      }
      var sbl_buy = results[i].selectSingleNode('./new_sblbuy');
      if (sbl_buy != null) {
        Xrm.Page.getAttribute("new_unitbuyprice").setValue(parseFloat(sbl_buy.text));
        window.sbl_data.org_price = parseFloat(sbl_buy.text);
      }
    }

    }
    else {
      Xrm.Page.getControl("new_unitbuyprice").setDisabled(true);
      Xrm.Page.getControl("new_unitsellprice").setDisabled(true);
      Xrm.Page.getControl("new_quantity").setDisabled(true);
    }
    }
    function new_marginpct_onchange()
    {
    var sbl_qty = 0;
    var sbl_marg = 0.0;
    var sbl_buy = 0.0;

    if (Xrm.Page.getAttribute("new_quantity").getValue() != null) {
      sbl_qty = Xrm.Page.getAttribute("new_quantity").getValue();
    }
    if (Xrm.Page.getAttribute("new_marginpct").getValue() != null) {
      sbl_marg = Xrm.Page.getAttribute("new_marginpct").getValue();
    }
    if (Xrm.Page.getAttribute("new_unitbuyprice").getValue() != null) {
      sbl_buy= Xrm.Page.getAttribute("new_unitbuyprice").getValue();
    }

    var sbl_sell = (sbl_buy * (1.0 / ((1.0 - (sbl_marg / 100.0)))));

    Xrm.Page.getAttribute("new_unitsellprice").setValue(sbl_sell);
    Xrm.Page.getAttribute("new_linetotal").setValue((sbl_qty * sbl_sell));
    Xrm.Page.getAttribute("new_totalmargin").setValue(((sbl_sell - sbl_buy) * sbl_qty));
    }
    function new_totalmargin_onchange()
    {
    Xrm.Page.getAttribute("new_quantity").fireOnChange();
    }
    function new_writeinproduct_onchange()
    {
    var sbl_writein = Xrm.Page.getAttribute("new_writeinproduct").getValue();

    if (sbl_writein) {
      Xrm.Page.getAttribute("new_productid").setValue(null);
      Xrm.Page.getControl("new_productid").setRequiredLevel('none');
      Xrm.Page.getControl("new_productid").setDisabled(true);
      Xrm.Page.getControl("new_partno").setDisabled(false);
      Xrm.Page.getControl("new_partno").setRequiredLevel('required');
      Xrm.Page.getControl("new_agreementtype").setRequiredLevel('none');
      window.sbl_data.org_price = 0.0;
      Xrm.Page.getControl("new_unitbuyprice").setDisabled(false);
      Xrm.Page.getControl("new_unitsellprice").setDisabled(false);
      Xrm.Page.getControl("new_quantity").setDisabled(false);
    }
    else {
      Xrm.Page.getControl("new_productid").setDisabled(false);
      Xrm.Page.getControl("new_productid").setRequiredLevel('required');
      //crmForm.SetFieldReqLevel("new_productid",true);
      Xrm.Page.getControl("new_partno").setDisabled(true);
      Xrm.Page.getControl("new_partno").setRequiredLevel('none');
      //crmForm.SetFieldReqLevel("new_partno",false);
      Xrm.Page.getControl("new_agreementtype").setRequiredLevel('required');
      //crmForm.SetFieldReqLevel('new_agreementtype',true);
    }

    Xrm.Page.getAttribute("new_unitbuyprice").fireOnChange();

    if (!sbl_writein) {
      Xrm.Page.getControl("new_unitbuyprice").setDisabled(true);
      Xrm.Page.getControl("new_unitsellprice").setDisabled(true);
      Xrm.Page.getControl("new_quantity").setDisabled(true);
    }
    }

    Wednesday, April 23, 2014 3:30 PM

All replies

  • There is no tool to convert the code for you. You can use the upgrade validator to flag all scripts that need updating, but you will need someone to re-write those scripts to update them for CRM 2013.
    • Proposed as answer by Nico-TMVP Wednesday, April 23, 2014 9:10 PM
    Wednesday, April 23, 2014 9:10 PM