零配件出库按钮(点击按钮,获取相关列表的多条选择id,传到类里面)
{!REQUIRESCRIPT ("/soap/ajax/41.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/40.0/apex.js")} var selectedIds = {!GETRECORDIDS($ObjectType.PartsAU__c)}; var partsAUids=''; if (selectedIds.length == 0) { alert('请选择一项'); }else{ selectedIds.forEach(function(item,index){ partsAUids+='\''+item+'\''; if(index!=selectedIds.length-1){ partsAUids +=','; } }); var array = []; var arrays = []; var partsAUQuery ="SELECT ID,Type__c,Status__c FROM PartsAU__c WHERE ID in ("+partsAUids+")"; result = sforce.connection.query(partsAUQuery); records = result.getArray("records"); records.forEach(function(item,index){ arrays.push(item.Id); if(item.Status__c=='已预约'){ array.push(item.Id); } }) if(array.sort().toString()==arrays.sort().toString()){ var result = sforce.apex.execute('SubmitRequestForApproval','BulkSubmitRequest',{partsAUList:array}); alert(result); }else{ alert('请选择已预约的零配件'); } }
通过按钮传过来的参数,触发工作流(多条)
// 零配件出库审批流 // submit to approve提交批准 WebService static String BulkSubmitRequest(List<String> partsAUList){ String ret='提交审批成功'; try{ Approval.ProcessSubmitRequest[] reqs = new Approval.ProcessSubmitRequest[]{}; for(String plist: partsAUList){ Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest(); //只能用String类型的参数 req.setComments('零配件出库审批'); req.setObjectId(plist); reqs.add(req); } Approval.ProcessResult[] result = Approval.process(reqs); }catch(Exception e){ //throw e; system.debug('BulkSubmitRequest error: '+e.getMessage()); } return ret; }
工单终止按钮,点击按钮,判断某个值时候为空,不为空就传值
{!REQUIRESCRIPT ("/soap/ajax/41.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/40.0/apex.js")} var reason = '{!WorkOrder.Reason__c}'; var oId = '{!WorkOrder.Id}'; if(reason==null || reason==''){ alert("请填写工单终止原因"); }else{ var arr = []; var sq = new sforce.SObject("WorkOrder"); sq.Id= oId; sq.Over__c = 'true'; arr.push(sq); var res=sforce.connection.update(arr); var result = sforce.apex.execute('SubmitRequestForApproval','SingleSubmitRequest',{id:oId,orderReason:reason}); alert(result); window.location.reload(); }
//工单终止 // submit to approve提交批准 WebService static String SingleSubmitRequest(String id,String orderReason){ String res='提交审批成功'; try{ //创建一个批准请求 Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest(); //设置需要提交的审批 req.setComments(orderReason); //要审批的记录Id req.setObjectId(id); //提交该批准请求 Approval.ProcessResult result = Approval.process(req); System.debug(result); }catch(Exception e){ res = e.getMessage(); //throw e; system.debug('SingleSubmitRequest error: '+e.getMessage()); } return res; }
点击按钮,改变对象的值
{!REQUIRESCRIPT ("/soap/ajax/41.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/40.0/apex.js")} var ww='{!ServiceQuote__c.Id}'; var partsAUids=''; var partsAUids ='\''+ww+'\''; var arr = []; var sq = new sforce.SObject("ServiceQuote__c"); sq.id = ww; sq.Status__c = '确认'; sq.OK__c = 'true'; arr.push(sq); var res=sforce.connection.update(arr); window.location.reload();