<?xml version="1.0" encoding="UTF-8"?>
|
<WebLink xmlns="http://soap.sforce.com/2006/04/metadata">
|
<fullName>Add_submit_approval_process</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")}
|
{!RequireScript("/resource/1527436225000/CommonUtilJs")}
|
//2021-10-22 gwy 版本更改为51.0
|
var getConnectDMLErrorMessages = function (results) {
|
var messages = [],
|
i = 0,
|
len = results.length,
|
r;
|
for (; i < len; i++) {
|
r = results[i];
|
if (!r.getBoolean("success")) {
|
messages = messages.concat(getConnectDMLMessagesOfAResult(r));
|
}
|
}
|
return messages;
|
};
|
var getConnectDMLMessagesOfAResult = function (res) {
|
var messages = [],
|
errors = res.getArray("errors"),
|
i = 0,
|
len = errors.length,
|
e;
|
for (; i < len; i++) {
|
e = errors[i];
|
messages.push(e.message + " " + getConnectDMLErrorFields(e));
|
}
|
return messages;
|
};
|
var getConnectDMLErrorFields = function (error) {
|
var fields = error.getArray('fields');
|
if (fields.length > 0) {
|
return "[" + fields.join(",") + "]"
|
} else {
|
return "";
|
}
|
};
|
|
var foo = function() {
|
var buttons = document.getElementsByName('Add_submit_approval_process'.toLowerCase());
|
for (var i=0; i<buttons.length; i++) {
|
buttons[i].className = "btnDisabled";
|
buttons[i].disabled = true;
|
}
|
/** OLY_OCM-251 start **/
|
var detailCAZ = new Array();
|
detailCAZ = sforce.connection.query("select Id from Rental_Apply_Equipment_Set_Detail__c where Rental_Apply__c='{!Rental_Apply__c.Id}' and Draft_Appended__c=1");
|
if ('{!Rental_Apply__c.Add_Approval_Status__c}' != '草案中' || detailCAZ.size == 0) {
|
alert('没有需要审批的追加附属品');
|
return;
|
}
|
/** OLY_OCM-251 end **/
|
if (!confirm("一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?")) {
|
return;
|
}
|
// 希望到货日不能早于申请提交日-0418追加
|
//if ('{!Rental_Apply__c.Request_shipping_day__c}' < '{!TODAY()}') {
|
// alert('希望到货日不能早于申请提交日');
|
// return;
|
// }
|
if('{!Rental_Apply__c.Repair__c}' != ''){
|
var DeliveryGood = new Array();
|
DeliveryGood = sforce.connection.query("select ReRepairObject_F__c,Status1__c,Agreed_Date__c,Repair_Estimated_date_formula__c,Repair_Final_Inspection_Date__c,Repair_Shipped_Date__c,Number_of_EffectiveContract__c, NewProductGuaranteeObject__c, Delivered_Product__r.Product2.Asset_Model_No__c from Repair__c where id ='{!JSENCODE(Rental_Apply__c.RepairId__c)}'");
|
var records= DeliveryGood.getArray("records");
|
if('{!Rental_Apply__c.Demo_purpose1__c}' == '维修代用' && '{!Rental_Apply__c.demo_purpose2__c}' == '一般用户'){
|
if (records[0].Repair_Estimated_date_formula__c == null) {
|
alert('一般维修无报价日,不可借用备品');
|
return;
|
}
|
else if (records[0].Repair_Estimated_date_formula__c < '2019-07-01' && records[0].Agreed_Date__c == null) {
|
alert('报价日在2019/7/1之前且户同意日为空,不可借用备品');
|
return;
|
}
|
}
|
if ('{!Rental_Apply__c.RecordTypeId}' != "01210000000RHIn"
|
&& '{!$Profile.Id}' != '00e10000000Y3o5'
|
&& records[0].NewProductGuaranteeObject__c == '8: 市场多年保修'
|
&& '{!Rental_Apply__c.demo_purpose2__c}' != '市场多年保修') {
|
alert('无偿区别标志为8: 市场多年保修,必须选择市场多年保修。');
|
}
|
if(records[0].Repair_Final_Inspection_Date__c != null){
|
alert('存在修理最终检测日,不可借用备品');
|
return;
|
}
|
if(records[0].Repair_Shipped_Date__c != null){
|
alert('存在RC修理返送日,不可借用备品');
|
return;
|
}
|
if(records[0].Status1__c =='0.删除' ||records[0].Status1__c =='0.取消' ||records[0].Status1__c =='5.完毕' ){
|
alert('修理已经结束,不能申请备品');
|
return;
|
}
|
if ( '{!Rental_Apply__c.demo_purpose2__c}' == '再修理' && records[0].ReRepairObject_F__c == 'false') {
|
alert('不属于再受理参考对象,不可借用备品');
|
return;
|
}
|
if ('{!Rental_Apply__c.RecordTypeId}' != '01210000000RHIn'
|
&& '{!Rental_Apply__c.demo_purpose2__c}' != '保修用户'
|
&& '{!Rental_Apply__c.demo_purpose2__c}' != '市场多年保修'
|
&& records[0].Number_of_EffectiveContract__c == '有' ) {
|
alert('有维修合同,必须选择保修用户.');
|
return;
|
}
|
var AssetModelNo = records[0].Delivered_Product__r.Product2.Asset_Model_No__c;
|
if ('{!Rental_Apply__c.RecordTypeId}' != '01210000000RHIn' && records[0].Number_of_EffectiveContract__c == '无'
|
&& (records[0].NewProductGuaranteeObject__c == '2: 服务多年保修'
|
&& (AssetModelNo == 'LTF-190-10-3D' || AssetModelNo == 'LTF-S190-5' || AssetModelNo == 'CYF-VHA' || AssetModelNo == 'CYF-VA2' || AssetModelNo == 'CYF-5A'|| AssetModelNo == 'LTF-S190-10'|| AssetModelNo == 'OER-AW'|| AssetModelNo == 'URF-V'|| AssetModelNo == 'URF-V2'|| AssetModelNo == 'URF-P6'))
|
&& '{!Rental_Apply__c.demo_purpose2__c}' != '保修用户' ) {
|
alert('此设备型号多年保修,请选择保修用户.');
|
return;
|
}
|
if ('{!Rental_Apply__c.RecordTypeId}' != '01210000000RHIn'
|
&& records[0].NewProductGuaranteeObject__c == '2: 服务多年保修'
|
&& (AssetModelNo == 'CV-V1' || AssetModelNo == 'CV-V1(A)' || AssetModelNo == 'CV-V1(B)' || AssetModelNo == 'GIF-LV1' || AssetModelNo == 'CF-LV1L' || AssetModelNo == 'CF-LV1I' || AssetModelNo == 'MAJ-1910')
|
&& ('{!Rental_Apply__c.demo_purpose2__c}' == '一般用户' || '{!Rental_Apply__c.demo_purpose2__c}' == '再修理')
|
) {
|
alert('奥辉设备,保修期内不提供备品.');
|
return;
|
}
|
}
|
|
|
if('{!Rental_Apply__c.Campaign__c}' != null && '{!Rental_Apply__c.Campaign__c}' != ''){
|
var DeliveryGood = new Array();
|
DeliveryGood = sforce.connection.query("select Status, Rental_Apply_Flag__c from Campaign where id ='{!Rental_Apply__c.CampaignId__c}'");
|
var records= DeliveryGood.getArray("records");
|
|
var interval = records[0].Status;
|
var records_Date = records[0].Rental_Apply_Flag__c;
|
if (interval == '草案中') {
|
alert('学会状态为草案中,不能提交');
|
return;
|
}
|
if (interval == '申请中') {
|
alert('学会状态为申请中,不能提交');
|
return;
|
}
|
if (interval == '已结束') {
|
alert('学会状态为已结束,不能提交');
|
return;
|
}
|
if (interval == '已提交报告') {
|
alert('学会状态为已提交报告,不能提交');
|
return;
|
}
|
if (interval == '取消申请中') {
|
alert('学会状态为取消申请中,不能提交');
|
return;
|
}
|
if (interval == '取消') {
|
alert('学会状态为取消,不能提交');
|
return;
|
}
|
}
|
|
if('{!Rental_Apply__c.QIS_number__c}' != null && '{!Rental_Apply__c.QIS_number__c}' != ''){
|
var DeliveryGood = new Array();
|
DeliveryGood = sforce.connection.query("select id,next_action__c from QIS_report__c where id ='{!Rental_Apply__c.QIS_ID_Line__c}'");
|
var records= DeliveryGood.getArray("records");
|
var interval = records[0].next_action__c;
|
if (interval == '送回') {
|
alert("QIS 已送回,不能再申请备品了");
|
return;
|
}
|
}
|
|
// share
|
var userAccess = new Array();
|
userAccess.push('{!Rental_Apply__c.applyUserId__c}_Edit');
|
|
//SWAG-BZMA8W 去掉 服务经理部长共享 start
|
//update lxy DLIU-BZNBG9 去掉服务经理部长共享
|
//userAccess.push('{!Rental_Apply__c.JingliApprovalManagerId__c}_Read');
|
//userAccess.push('{!Rental_Apply__c.SalesManagerId__c}_Read');//20210727 ljh SFDC-C54C33 update 共享触发器完成
|
//update lxy DLIU-BZNBG9 去掉服务经理部长共享
|
//userAccess.push('{!Rental_Apply__c.BuchangApprovalManagerId__c}_Read');
|
//SWAG-BZMA8W 去掉 服务经理部长共享 end
|
//userAccess.push('{!Rental_Apply__c.BuchangApprovalManagerSalesId__c}_Read');//20210727 ljh SFDC-C54C33 update 共享触发器完成
|
//userAccess.push('{!Rental_Apply__c.ZongjianApprovalManagerId__c}_Read');//20210727 ljh SFDC-C54C33 update 共享触发器完成
|
//userAccess.push('{!Rental_Apply__c.Status__c}_Read');
|
|
var rtn = sforce.apex.execute('ControllerUtil','setSObjectShare',{sobjectName:'Rental_Apply__Share',rowCause:'ApplyUserShare__c',parentId:'{!Rental_Apply__c.Id}',userAccess:userAccess,ownerId:'{!Rental_Apply__c.OwnerId}'});
|
if (rtn != 'OK') {
|
alert(rtn);
|
return;
|
}
|
|
//追加备品申请状态确认,已经提交过的申请,不能重复提交Status__c
|
if ('{!Rental_Apply__c.Status__c}' != '已批准' &&
|
'{!Rental_Apply__c.Status__c}' != '已出库指示') {
|
alert('请备品申请状态确认,申请状态已批准后才可以提交追加审批');
|
return;
|
}
|
|
var rac = new sforce.SObject("Rental_Apply__c");
|
rac.Id = "{!Rental_Apply__c.Id}";
|
rac.Add_Approval_Status__c = "填写完毕";
|
//状态修改成填写完毕后会在Handler里面更新追加的附属品信息
|
var result = sforce.connection.update([rac]);
|
var messages = getConnectDMLErrorMessages(result);
|
if (messages.length > 0) {
|
alert(messages.join("\n"));
|
return;
|
}
|
|
var request = new sforce.ProcessSubmitRequest();
|
request.objectId = "{!Rental_Apply__c.Id}";
|
var processResults = sforce.connection.process([request]);
|
|
if (processResults[0].errors != null) {
|
var back = new sforce.SObject("Rental_Apply__c");
|
back.Id = "{!Rental_Apply__c.Id}";
|
back.Add_Approval_Status__c = "草案中";
|
var backResult = sforce.connection.update([back]);
|
backMessages = getConnectDMLErrorMessages(backResult);
|
if (backMessages.length > 0) {
|
alert(backMessages.join("\n"));
|
return;
|
}
|
|
var errmsg = processResults[0].errors.message.toString();
|
alert(errmsg);
|
return;
|
}
|
window.location.href = window.location;
|
};
|
foo();</url>
|
</WebLink>
|