2. 約會的差旅費頁面:
a.距離欄位:依起點去判斷,服務"差旅費中的從台中到達或從台北到達將其值帶入。
b.總里程數欄位:依單程/來回的值區分,\
單程:距離 + 調整欄位值
來回:距離 * 2
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
function getothers(customerid){
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:QueryExpression\">" +
" <q1:EntityName>var_travelspend</q1:EntityName>" +
" <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
" <q1:Attributes>" +
" <q1:Attribute>var_visitaccount</q1:Attribute>" +
" <q1:Attribute>var_km</q1:Attribute>" +
" <q1:Attribute>var_km1</q1:Attribute>" +
" </q1:Attributes>" +
" </q1:ColumnSet>" +
" <q1:Distinct>false</q1:Distinct>" +
" <q1:PageInfo>" +
" <q1:PageNumber>1</q1:PageNumber>" +
" <q1:Count>1</q1:Count>" +
" </q1:PageInfo>" +
" <q1:Criteria>" +
" <q1:FilterOperator>And</q1:FilterOperator>" +
" <q1:Conditions>" +
" <q1:Condition>" +
" <q1:AttributeName>var_visitaccount</q1:AttributeName>" +
" <q1:Operator>Equal</q1:Operator>" +
" <q1:Values>" +
" <q1:Value xmlns:q2=\"http://microsoft.com/wsdl/types/\" xsi:type=\"q2:guid\">"+customerid+"</q1:Value>" +
" </q1:Values>" +
" </q1:Condition>" +
" </q1:Conditions>" +
" </q1:Criteria>" +
" </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);
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.loadXML(xmlHttpRequest.responseXML.xml);
if (xmlDoc.selectSingleNode("//q1:var_km") !=null && xmlDoc.selectSingleNode("//q1:var_km1") !=null)
{
var km=crmForm.all.var_origin.DataValue==1?xmlDoc.selectSingleNode("//q1:var_km").text:xmlDoc.selectSingleNode("//q1:var_km1");
crmForm.all.var_origin.km1=parseFloat(xmlDoc.selectSingleNode("//q1:var_km").text);
crmForm.all.var_origin.km2=parseFloat(xmlDoc.selectSingleNode("//q1:var_km1").text);
}
setTotalkm();
}
//設置總里程數欄位的值.
function setTotalkm()
{
crmForm.all.var_km.DataValue=crmForm.all.var_origin.DataValue==1?crmForm.all.var_origin.km1:crmForm.all.var_origin.km2;
if (crmForm.all.var_oneway.DataValue==1)
{
crmForm.all.var_totalkm.DataValue=parseFloat( crmForm.all.var_regulate.DataValue==null?crmForm.all.var_km.DataValue:crmForm.all.var_km.DataValue+crmForm.all.var_regulate.DataValue);
}
else
{
crmForm.all.var_totalkm.DataValue=crmForm.all.var_km.DataValue*2;
}
}
//var oSN = crmForm.all.new_serialno; //序號欄位名稱
var oName = crmForm.all.var_tovisit; //自動生成的name欄位名稱
var lookupItem = crmForm.all.var_customerid; //產品名稱欄位
if (lookupItem.DataValue != null)
{
oName.DataValue=lookupItem.DataValue[0].name;
crmForm.all.location.DataValue =lookupItem.items[0].keyValues.address1_line1.value;
getothers(lookupItem.DataValue[0].id);
}