zoukankan      html  css  js  c++  java
  • everspring Quote Product OnLoad


    function OnCrmPageLoad()
    {

      
    //提供Function在On Save調用.
        crmForm.getq1AttributesString=_getq1AttributesString;
        crmForm.getq1AttributesValue
    =_getq1AttributesValue;
       crmForm.getDynamicEnitity
    =_getDynamicEnitity;
        crmForm.queryByAttribute
    =_queryByAttribute;
        crmForm.queryByAttributeFieldValue
    =_queryByAttributeFieldValue;
       crmForm.getEntityPropertyValue
    =_getEntityPropertyValue;
       crmForm.getProductPriceLevelXml 
    =_getProductPriceLevelXml ;
       crmForm.var_refreshPriceperunit
    =_var_refreshPriceperunit;
      crmForm.getFetchXml
    =_getFetchXml;
      
    var quoteidvalue =crmForm.all.quoteid.DataValue;
    //新增時預設採用priceoverriden的方式
    if (crmForm.FormType == 1)
    {
             crmForm.all.ispriceoverridden.DataValue
    =true;
             crmForm.all.priceperunit.Disabled
    =false;
    }
    if (crmForm.all.isproductoverridden.DataValue == 1)
     {
       crmForm.all.esp_productnumber.Disabled
    =false;
     }
    else
     {
       crmForm.all.esp_productnumber.Disabled
    =true;
       crmForm.all.esp_productnumber.ForceSubmit
    =true;

     }
        
    var productidLookup=crmForm.all.productid;

    var retxml=crmForm.getProductPriceLevelXml(quoteidvalue );

    var pricelevelidvalue= crmForm.getEntityPropertyValue(retxml.xml, "pricelevelid")

      
    var filterfetchxml="<fetch mapping='logical'><entity name='product'>"  + "<filter type='or'><condition attribute='pricelevelid' operator='eq' value='" + pricelevelidvalue + "' /><condition attribute='pricelevelid' operator='eq' value='9439FF4D-8613-DE11-B063-001EC9B6EAFD' /> </filter></entity></fetch>";

    //   productidLookup.AddParam("search",filterfetchxml);
      }

    OnCrmPageLoad();

    function _var_refreshPriceperunit()
    {
        
    if (crmForm.all.ispriceoverridden.DataValue==true)
        {

                 
    var quoteidvalue =crmForm.all.quoteid.DataValue;
                 
    var retxml=crmForm.getProductPriceLevelXml(quoteidvalue );
                  
    var quotetransactioncurrencyid=crmForm.getEntityPropertyValue(retxml.xml, "transactioncurrencyid")
                  
    var pricelevelidvalue= crmForm.getEntityPropertyValue(retxml.xml, "pricelevelid")

                  
    var queryAttributes=new Array("pricelevelid","productid","uomid");
                    
    var columnsetAttributes=new Array("amount" , "transactioncurrencyid");
                   
    var queryAttributesValue=new Array(pricelevelidvalue,crmForm.all.productid.DataValue[0].id, crmForm.all.uomid.DataValue[0].id);
          
    var            resultXml=crmForm.queryByAttribute("productpricelevel",columnsetAttributes,queryAttributes,queryAttributesValue);
                      
    var priceperunitvalue= crmForm.queryByAttributeFieldValue(resultXml.xml,"amount");
                       
    var priceleveltransactioncurrencyid= crmForm.queryByAttributeFieldValue(resultXml.xml,"transactioncurrencyid");

         
    if (isNaN(parseFloat(priceperunitvalue))==true)
        {

                    
    var queryAttributesValue2=new Array("9439FF4D-8613-DE11-B063-001EC9B6EAFD",crmForm.all.productid.DataValue[0].id, crmForm.all.uomid.DataValue[0].id);
                       
    var columnsetAttributes2=new Array("amount""transactioncurrencyid" );
                       
    var queryAttributes2=new Array("pricelevelid","productid","uomid");
                      
    var resultXml2=crmForm.queryByAttribute("productpricelevel",columnsetAttributes2,queryAttributes2,queryAttributesValue2);

                        priceperunitvalue
    = crmForm.queryByAttributeFieldValue(resultXml2.xml,"amount");

                         priceleveltransactioncurrencyid
    = crmForm.queryByAttributeFieldValue( resultXml2.xml,"transactioncurrencyid" );
        }
               
    var fetchExchangeRateXml="<fetch mapping='logical'>" +
            
    "<entity name='transactioncurrency'>" +
           
    "<attribute name='exchangerate'/>" +
           
    "<filter type='or'>" +
           
    "<condition attribute='transactioncurrencyid' operator ='eq' value='"+quotetransactioncurrencyid+"'/>" +
           
    "<condition attribute='transactioncurrencyid' operator ='eq' value='"+priceleveltransactioncurrencyid+"'/>" +
           
    "</filter>" +
           
    "</entity>" +
           
    "</fetch>"
                    
    var fetchResult= crmForm.getFetchXml(CrmEncodeDecode.CrmXmlEncode(fetchExchangeRateXml));

            
    var fetchresultvalue=CrmEncodeDecode.CrmXmlDecode(fetchResult.xml);

             
    var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async
    =false;
            xmlDoc.loadXML(fetchresultvalue.toLowerCase());
          
    var querypath = "//result[transactioncurrencyid='{"+quotetransactioncurrencyid.toLowerCase()+"}']/exchangerate";
            
    var quoteexchangerate="";
            
    var pricelevelexchangerate="";
           
    var ret=xmlDoc.selectSingleNode(querypath );
             
    if (ret==null | ret==undefined)
            {
                  alert(
    "quote transcation currencyid"+quotetransactioncurrencyid.toLowerCase()+" not found.");
            }
            
    else
             {
                quoteexchangerate
    =ret.text;
             }

           querypath 
    = "//result[transactioncurrencyid='"+priceleveltransactioncurrencyid.toLowerCase()+"']/exchangerate";

           ret
    =xmlDoc.selectSingleNode(querypath);
             
    if (ret==null | ret==undefined)
            {
                  alert(
    "price level transcation currencyid"+priceleveltransactioncurrencyid.toLowerCase()+" not found.");
            }
            
    else
             {
                pricelevelexchangerate
    =ret.text;
             }



                 
    if (isNaN(parseFloat(priceperunitvalue))==false && isNaN(parseFloat(pricelevelexchangerate)) ==false &&  isNaN(parseFloat(priceperunitvalue))==false )
                {
                         
                          crmForm.all.priceperunit.DataValue
    =parseFloat(priceperunitvalue) * parseFloat(quoteexchangerate)/parseFloat(pricelevelexchangerate);

                         crmForm.all.priceperunit.ForceSubmit
    =true;


                }
         
        }
    }
    function _getProductPriceLevelXml(entityId)
    {
    var attributeNames=new Array("pricelevelid","transactioncurrencyid","exchangerate")

    var resultXml=crmForm.getDynamicEnitity("quote",entityId,attributeNames);
    return resultXml;

    }
    function _getFetchXml(fetchXml)
    {
        
    var xml = "" + 
    "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + 
    "<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\">" + GenerateAuthenticationHeader()+"  <soap:Body>" + 
    "    <Fetch xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
    "      <fetchXml>" + fetchXml+
    "      </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;
    return resultXml;
    }
    function _getDynamicEnitity(entityName, entityId,columnsetAttributes)
    {
        
    var xml = "" + 
    "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + 
    "<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\">" + GenerateAuthenticationHeader()+"  <soap:Body>" + 
    "    <Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
    "      <Request xsi:type=\"RetrieveRequest\" ReturnDynamicEntities=\"true\">" + 
    "        <Target xsi:type=\"TargetRetrieveDynamic\">" + 
    "          <EntityName>"+entityName+"</EntityName>" + 
    "          <EntityId>"+entityId+"</EntityId>" + 
    "        </Target>" + 
    "        <ColumnSet xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:ColumnSet\">" + 
    "          <q1:Attributes>" + crmForm.getq1AttributesString(columnsetAttributes) + 
    "          </q1:Attributes>" + 
    "        </ColumnSet>" + 

    "      </Request>" + 
    "    </Execute>" + 
    "  </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/Execute");
    xmlHttpRequest.setRequestHeader(
    "Content-Type""text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader(
    "Content-Length", xml.length);
    xmlHttpRequest.send(xml);

    var resultXml = xmlHttpRequest.responseXML;
    return resultXml;
    }


    function _getEntityPropertyValue(resultXml, attributeName)
    {

    // Create an XML object to parse the results.
    var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async
    =false;
    xmlDoc.loadXML(resultXml);

    var ret=xmlDoc.selectSingleNode("//Property[@Name='"+attributeName+"']");

    //ret.text enough for return xml;
    //
    in other case this may not enough be careful for this.
    return ret.text;


    }

    function _getq1AttributesString(attributes)
    {
       
       
    var strRet="";
       
    for(i=0;i<attributes.length;i++)
      {
        strRet
    +=("<q1:Attribute>"+attributes[i]+"</q1:Attribute>") ;

        
      }
       
    return strRet;
    }

    function _getq1AttributesValue(attributes)
    {
       
       
    var strRet="";
       
    for(i=0;i<attributes.length;i++)
      {
        strRet
    +=("<q1:Value xsi:type=\"xsd:string\">"+attributes[i]+"</q1:Value>");

        
      }
       
    return strRet;
    }

    function _queryByAttribute(entityName, columnsetAttributes, queryAttributes, queryAttributesValue)
    {

    var xml = "" + 
    "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + 
    "<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\">" +GenerateAuthenticationHeader() +
    "  <soap:Body>" + 
    "    <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
    "      <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryByAttribute\">" + 
    "        <q1:EntityName>"+entityName+"</q1:EntityName>" + 
    "        <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" + 
    "          <q1:Attributes>" + crmForm.getq1AttributesString(columnsetAttributes)+ 
    "          </q1:Attributes>" + 
    "        </q1:ColumnSet>" + 
    "        <q1:Attributes>" + crmForm.getq1AttributesString(queryAttributes)+ 
    "        </q1:Attributes>" + 
    "        <q1:Values>" + crmForm.getq1AttributesValue(queryAttributesValue) + 
    "        </q1:Values>" + 
    "      </query>" + 
    "    </RetrieveMultiple>" + 
    "  </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/RetrieveMultiple");
    xmlHttpRequest.setRequestHeader(
    "Content-Type""text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader(
    "Content-Length", xml.length);
    xmlHttpRequest.send(xml);

    var resultXml = xmlHttpRequest.responseXML;
    return resultXml;
    }

    function _queryByAttributeFieldValue(resultXml,fieldName)
    {
         
    var oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        oXmlDoc.async 
    = false
        
    // Load the document that has the results.
        oXmlDoc.loadXML(resultXml);
        
    var fieldElement=oXmlDoc.selectSingleNode("//q1:"+fieldName);
        
    return (fieldElement== null)? " " :fieldElement.text
    }



    //queryByAttribute("productpricelevel",columnsetAttributes,queryAttributes,queryAttributesValue);
  • 相关阅读:
    推介一款小工具——SwitchHosts
    Postman的使用之进行文件上传
    Postman的使用之普通的提交Post和Get请求
    Postman的安装
    Windows配置基础环境(jdk+tomcat)
    yum clean all大坑解决
    通过代理实现访问内网系统
    批量配置免密登录
    设置JRebel热部署【本地模式】
    使用多线程程序模拟实现单生产者/多消费者问题 (Linux 线程锁实践)
  • 原文地址:https://www.cnblogs.com/janmson/p/1435334.html
Copyright © 2011-2022 走看看