| <?xml version="1.0" encoding="UTF-8"?> | 
| <WebLink xmlns="http://soap.sforce.com/2006/04/metadata"> | 
|     <fullName>newOpp</fullName> | 
|     <availability>online</availability> | 
|     <displayType>button</displayType> | 
|     <linkType>javascript</linkType> | 
|     <masterLabel>开始询价</masterLabel> | 
|     <openType>onClickJavaScript</openType> | 
|     <protected>false</protected> | 
|     <url>{!REQUIRESCRIPT("/soap/ajax/51.0/connection.js")}; | 
| {!REQUIRESCRIPT("/soap/ajax/51.0/apex.js")}; | 
| //2021-10-22 gwy 版本更改为51.0 | 
| // 获取SI产品区分的名字 | 
| var ProductTypes_query = "Select id, Name From ProductTypes__c WHERE id = 'a2b10000001Hvre'"; | 
| var ProductTypes_records = sforce.connection.query(ProductTypes_query).getArray('records'); | 
| var SI_Name; | 
| if (ProductTypes_records != null && ProductTypes_records.length > 0) { | 
| SI_Name = ProductTypes_records[0].Name; | 
| } | 
| //如果需要进行SI询价,跳转Create_Opportunity_by_Agency_Opportunity | 
| var doubleFlg = false; | 
| if (!doubleFlg) { | 
| doubleFlg = true; | 
| var newflag = true; | 
| if ('{!Agency_Opportunity__c.Change_To_Opportunity__c}' != '') { | 
| newflag = false; | 
| alert("已经转成过【OCSM询价】。"); | 
| var inputs=document.getElementsByName("newopp"); | 
|     for(var i=0;i<inputs.length;i++){ | 
|         var input=inputs[i]; | 
|         input.setAttribute('disabled','disabled'); | 
| input.setAttribute('class','btnDisabled'); | 
|    } | 
| } | 
| if (newflag) { | 
| if ('{!Agency_Opportunity__c.Product_Category1__c}' == SI_Name || '{!Agency_Opportunity__c.Product_Category2__c}' == SI_Name || | 
| '{!Agency_Opportunity__c.Product_Category3__c}' == SI_Name) { | 
| window.open("/apex/Create_Opportunity_by_Agency_Opportunity?id={!URLENCODE(Agency_Opportunity__c.Id)}"); | 
| } else { | 
| var doubleFlg = false; | 
| var query = "Select QualifiedApiName, EntityDefinition.KeyPrefix, DurableId From FieldDefinition WHERE EntityDefinition.QualifiedApiName = 'Opportunity'"; | 
| records = sforce.connection.query(query).getArray('records'); | 
| var prefix, | 
| fId_Opportunity_Category__c, | 
| fId_Close_Forecasted_Date__c, | 
| fId_Opportunity_stage__c, | 
| fId_Hospital__c, | 
| fId_SAP_Province__c, | 
| fId_Agency_Opportunity__c, | 
| fId_Sales_Root__c, | 
| fId_Trade__c, | 
| fId_Promise_Class__c, | 
| fId_Bid_Planned_Date__c, | 
| fId_Department_Class__c, | 
| fId_Account; | 
| for (var i = 0; i < records.length; i++) { | 
| var record = records[i]; | 
| prefix = record.EntityDefinition.KeyPrefix.toString(); | 
| if (record.QualifiedApiName == 'Opportunity_Category__c') | 
| fId_Opportunity_Category__c = record.DurableId.toString().split('.')[1]; | 
| if (record.QualifiedApiName == 'Close_Forecasted_Date__c') | 
| fId_Close_Forecasted_Date__c = record.DurableId.toString().split('.')[1]; | 
| if (record.QualifiedApiName == 'Opportunity_stage__c') | 
| fId_Opportunity_stage__c = record.DurableId.toString().split('.')[1]; | 
| if (record.QualifiedApiName == 'Hospital__c') | 
| fId_Hospital__c = record.DurableId.toString().split('.')[1]; | 
| if (record.QualifiedApiName == 'SAP_Province__c') | 
| fId_SAP_Province__c = record.DurableId.toString().split('.')[1]; | 
| if (record.QualifiedApiName == 'Agency_Opportunity__c') | 
| fId_Agency_Opportunity__c = record.DurableId.toString().split('.')[1]; | 
| if (record.QualifiedApiName == 'Sales_Root__c') | 
| fId_Sales_Root__c = record.DurableId.toString().split('.')[1]; | 
| if (record.QualifiedApiName == 'Trade__c') | 
| fId_Trade__c = record.DurableId.toString().split('.')[1]; | 
| if (record.QualifiedApiName == 'Promise_Class__c') | 
| fId_Promise_Class__c = record.DurableId.toString().split('.')[1]; | 
| if (record.QualifiedApiName == 'Bid_Planned_Date__c') | 
| fId_Bid_Planned_Date__c = record.DurableId.toString().split('.')[1]; | 
| if (record.QualifiedApiName == 'Department_Class__c') | 
| fId_Department_Class__c = record.DurableId.toString().split('.')[1]; | 
| } | 
| var accountName = "{!Agency_Opportunity__c.Department_Class_Opp_Name__c}" + ' ' + "{!Agency_Opportunity__c.Department_Name_Text__c}"; | 
| console.log(accountName ); | 
| var AccountQuery = "Select id, name From Account WHERE Name = \'" + accountName +"\'"; | 
| console.log(AccountQuery ); | 
| var accountrecords = sforce.connection.query(AccountQuery).getArray('records'); | 
| console.log(accountrecords ); | 
| var accountID = ''; | 
| if(accountrecords.length > 0){ | 
| accountID = accountrecords[0].Id; | 
| } | 
| console.log('accountID:'+accountID); | 
| var openURL = "/006/e?retURL=%2F{!URLENCODE(Agency_Opportunity__c.Id)}" + | 
| "&RecordType=01210000000QekK" + | 
| "&ent=Opportunity&opp11=引合" + | 
| "&" + fId_Opportunity_Category__c + "={!URLENCODE(text(Agency_Opportunity__c.Department_Cateogy__c))}" + | 
| "&opp3={!Agency_Opportunity__c.Name}" + | 
| "&" + fId_Close_Forecasted_Date__c + "={!Agency_Opportunity__c.Close_Forecasted_Date__c}" + | 
| "&" + fId_Bid_Planned_Date__c + "={!Agency_Opportunity__c.Bid_Planned_Date__c}" + | 
| "&" + fId_Opportunity_stage__c + "={!URLENCODE(text(Agency_Opportunity__c.StageName__c))}" + | 
| "&CF" + fId_Hospital__c + "={!URLENCODE(Agency_Opportunity__c.hosName_opp__c)}" + | 
| "&CF" + fId_Hospital__c + "_lkid={!URLENCODE(Agency_Opportunity__c.hosId_opp__c)}" + | 
| "&" + fId_SAP_Province__c + "={!URLENCODE($User.Province_Text__c)}" + | 
| "&CF" + fId_Agency_Opportunity__c + "_lkid={!URLENCODE(Agency_Opportunity__c.Id)}" + | 
| "&CF" + fId_Agency_Opportunity__c + "={!URLENCODE(Agency_Opportunity__c.Name)}" + | 
| "&opp6=经销商" + | 
| "&" + fId_Sales_Root__c + "=販売店" + | 
| "&" + fId_Trade__c + "=内貿" + | 
| "&" + fId_Promise_Class__c + "=内貿" + | 
| "&opp4={!URLENCODE(Agency_Opportunity__c.Department_Class_Opp_Name__c) + ' ' + URLENCODE(Agency_Opportunity__c.Department_Name_Text__c)}" + | 
|   | 
|                                                                               | 
|                                         | 
|                                           | 
|                                                                                                                  | 
|                                                 | 
|                                                                                                     | 
|                                                                                           | 
|                                                                                                      | 
|                                                                                           | 
|                                                                                              | 
|                                                                               | 
|                                                                                              | 
|                                                                                           | 
|                             | 
|                                                  | 
|                                          | 
|                                                  | 
| "&CF" + fId_Department_Class__c + "={!URLENCODE(Agency_Opportunity__c.Department_Class_Opp_Name__c)}" + | 
| "&CF" + fId_Department_Class__c + "_lkid={!URLENCODE(Agency_Opportunity__c.Department_Class_OppId__c)}"; | 
|   | 
| if(!!accountID){ | 
| openURL = openURL + "&opp4_lkid=" + accountID; | 
| } | 
|   | 
| window.open(openURL); | 
| } | 
| } | 
| }</url> | 
| </WebLink> |