Module
新建页面
order 100
order 101
Create New
Link type:URL(form Arguments)
Arguments : x_dchhl_dch_ca_ca_request.do?sys_id=-1&sysparm_stack=x_dchhl_dch_ca_ca_request_list.do
Script基础:
!g_form.isNewRecord(); //没有新字段产生
g_form.clearValue('u_dch_type'); //清空该字段的值
g_form.setReadOnly('u_dch_type', true); //该字段设置为可读
g_form.setMandatory('u_dch_type', true); //该字段为必填
g_form.setVisible('u_dch_type', true); //显示该字段
g_form.setValue('u_dch_type', type1); //修改字段的值为type1
g_form.setLabelOf('u_dch_type', '类型'); //修改字段的标签
1.下拉level选项,带出对应字段名
client Script
switch(g_form.getValue('brand_type')){
case '':
g_form.setVisible('u_dch_ca_note', false);
break;
case 'Service brands':
g_form.setVisible('u_dch_ca_note', true);
if(g_form.getLabelOf('brand_type')=='Region level'){
g_form.setLabelOf('u_dch_ca_note', '111');
}
else{
g_form.setLabelOf('u_dch_ca_note', '一号');
}
break;
case 'Agency brands':
g_form.setVisible('u_dch_ca_note', true);
if(g_form.getLabelOf('brand_type')=='Region level'){
g_form.setLabelOf('u_dch_ca_note', '222');
}
else{
g_form.setLabelOf('u_dch_ca_note', '二号');
}
break;
}
2.冲销单据:
client Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) { if(g_form.isNewRecord()){ var ga = new GlideAjax('DCH_CACN_GetKeSuTable'); ga.addParam('sysparm_name','getKeSuTable'); ga.addParam('chongxiao', g_form.getValue('u_ca_chongxiaodanju')); ga.getXML(populateField); } function populateField(response){ var ScriptInclude = response.responseXML.documentElement.getAttribute("answer"); //var arrd = ScriptInclude.split("ssh1"); //jslog(typeof(ScriptInclude)); //jslog(ScriptInclude); var obj = JSON.parse(ScriptInclude); g_form.setValue('u_dch_ca_application_type',obj.a); g_form.setValue('u_dch_ca_date_of_application',obj.b); g_form.setValue('u_dch_ca_date_of_the_guest_complaint',obj.c); g_form.setValue('u_dch_ca_event_area',obj.d); g_form.setValue('u_dch_ca_customer_complaints',obj.e); g_form.setValue('u_dch_ca_customer_complaint_amount',obj.f); g_form.setValue('u_dch_ca_cost_bearer',obj.g); //g_form.setValue('brand_type',obj.h); g_form.setValue('ca_approver',obj.i); g_form.setValue('u_dch_ca_company_name',obj.j); g_form.setValue('u_dch_ca_corporate_account_number',obj.k); g_form.setValue('u_dch_ca_customer_complaints_invoice_number',obj.l); g_form.setValue('u_dch_ca_customer_name',obj.m); g_form.setValue('u_dch_ca_bank_card_number',obj.n); g_form.setValue('u_dch_ca_identification_number',obj.o); g_form.setReadOnly('u_dch_ca_application_type', true); g_form.setReadOnly('u_dch_ca_date_of_application', true); g_form.setReadOnly('u_dch_ca_date_of_the_guest_complaint', true); g_form.setReadOnly('u_dch_ca_event_area', true); g_form.setReadOnly('u_dch_ca_customer_complaints', true); g_form.setReadOnly('u_dch_ca_customer_complaint_amount', true); g_form.setReadOnly('u_dch_ca_cost_bearer', true); //g_form.setReadOnly('brand_type', true); g_form.setReadOnly('ca_approver', true); g_form.setReadOnly('u_dch_ca_company_name', true); g_form.setReadOnly('u_dch_ca_corporate_account_number', true); g_form.setReadOnly('u_dch_ca_customer_complaints_invoice_number', true); g_form.setReadOnly('u_dch_ca_customer_name', true); g_form.setReadOnly('u_dch_ca_bank_card_number', true); g_form.setReadOnly('u_dch_ca_identification_number', true); } }
Include Script
var DCH_CACN_GetKeSuTable = Class.create(); DCH_CACN_GetKeSuTable.prototype = Object.extendsObject(global.AbstractAjaxProcessor, { getKeSuTable: function(){ var userRecord = new GlideRecord('x_dchhl_dch_ca_loan'); userRecord.get(this.getParameter('chongxiao')); var obj ={"a":userRecord.u_dch_ca_application_type.toString(),"b":userRecord.u_dch_ca_date_of_application.toString(),"c":userRecord.u_dch_ca_date_of_the_guest_complaint.toString(),"d":userRecord.u_dch_ca_event_area.toString(),"e":userRecord.u_dch_ca_customer_complaints.toString(),"f":userRecord.u_dch_ca_customer_complaint_amount.toString(),"g":userRecord.u_dch_ca_cost_bearer.toString(),"i":userRecord.ca_approver.toString(),"j":userRecord.u_dch_ca_company_name.toString(),"k":userRecord.u_dch_ca_corporate_account_number.toString(),"l":userRecord.u_dch_ca_customer_complaints_invoice_number.toString(),"m":userRecord.u_dch_ca_customer_name.toString(),"n":userRecord. u_dch_ca_bank_card_number.toString(),"o":userRecord. u_dch_ca_identification_number.toString()}; var ScriptInclude = JSON.stringify(obj); return ScriptInclude; }, type: 'DCH_CACN_GetKeSuTable' });
3.带出签核人
Include Script
function DCH_CACN_GetAllFirstApprover(){ var firstApprover = []; var regionLevel=current.brand_type; var thresholdTable = new GlideRecord('x_dchhl_dch_ca_credit_limit'); thresholdTable.addQuery("brand_type",regionLevel); thresholdTable.query(); var criteriaId =''; while (thresholdTable.next()){ if (criteriaId.length == 0){ criteriaId += (thresholdTable.sys_id); }else{ criteriaId+=(',' + thresholdTable.sys_id); } } gs.info('criteriaIds:'+ criteriaId); var approverChain = new GlideRecord('x_dchhl_dch_ca_approver_chain'); approverChain.addQuery('criteria_id','IN',criteriaId); //approverChain.addQuery('criteria_id',criteriaId); approverChain.query(); while (approverChain.next()){ firstApprover.push(approverChain.approver_level_1.sys_id); } gs.info('Number of Approver: '+firstApprover.length); var currentUserId = gs.getUserID(); gs.info('currentUserId:' + currentUserId); var newCAUtilClass = new DCH_CACN_UtilClass(); var currentUserDetail = newCAUtilClass.returnEmployeeInfo(currentUserId); var currentUserCom=currentUserDetail.ca_belongs_to_the_company; var firstApproverUserId = ''; var employee = new GlideRecord('x_dchhl_dch_ca_employee'); employee.addQuery('ca_associated_user',firstApprover); employee.addQuery('ca_belongs_to_the_company',currentUserCom); employee.query(); while (employee.next()){ if (firstApproverUserId.length == 0){ firstApproverUserId += (employee.sys_id); }else{ firstApproverUserId+=(',' + employee.sys_id); } } //gs.info('firstApproverUserId11:'+ firstApproverUserId); return 'sys_id IN' + firstApproverUserId; }
4.提交单据:
Business Rules
(function executeRule(current, previous /*null when async*/) { //gs.info('DCH_CACN_CARequest_BeforeInsert'); var newCAUtilClass = new DCH_CACN_UtilClass(); var currentUserId = gs.getUserID(); //gs.info('currentUserId:' + currentUserId); var employeeDetail = newCAUtilClass.returnEmployeeInfo(currentUserId); if(employeeDetail == undefined){ gs.addErrorMessage("申请人不在员工表中,无法进行申请操作。"); current.setAbortAction(true); } var errorMessageApprover = gs.getMessage('DCH_CACN_ApproverAsYourself'); var errorMessageNOApproverChain = gs.getMessage('DCH_CACN_NoApproverChainFound'); gs.info('employeeDetail:' + employeeDetail.ca_employee_id); //Define the state ='Draft' current.status = '1'; current.ca_applyuser=employeeDetail.ca_employee_name; current.ca_belongs_to_the_company=employeeDetail.ca_belongs_to_the_company.ca_company_name; if (current.ca_approver == employeeDetail.sys_id){ gs.addErrorMessage(errorMessageApprover); current.setAbortAction(true); } else{ //gs.info('Trigger Find Approval Route'); //gs.info('current.u_dch_ap_total_request_amount: '+current.u_dch_ap_total_request_amount); var type = current.brand_type; var totalAmt = current.adjust_amount; var threshold = newCAUtilClass.getThreshold(type, totalAmt); if (threshold == undefined){ gs.addErrorMessage("11111111111111111"); current.setAbortAction(true); } else{ var thresholdId = threshold.sys_id; gs.info('confirmed:'+threshold.brand_type+'-'+threshold.maximum_amount); var approverUserId = newCAUtilClass.getUserId(current.ca_approver); var currentUserCompany = employeeDetail.ca_belongs_to_the_company; var approverChain = newCAUtilClass.returnApproverChain(approverUserId,currentUserCompany,thresholdId); //var approverChain = newCAUtilClass.returnApproverChain(approverUserId,currentUserCompany,currentUserDept); if (approverChain){ gs.info('approverChain:'+approverChain.company); current.approver_level_1 = approverChain.approver_level_1; current.approver_level_2 = approverChain.approver_level_2; current.approver_level_3 = approverChain.approver_level_3; current.approver_level_4 = approverChain.approver_level_4; current.approver_level_5 = approverChain.approver_level_5; current.approver_level_6 = approverChain.approver_level_6; current.approver_level_7 = approverChain.approver_level_7; current.approver_level_8 = approverChain.approver_level_8; current.approver_level_9 = approverChain.approver_level_9; current.approver_level_10 = approverChain.approver_level_10; current.approver_level_11 = approverChain.approver_level_11; current.ca_approver_level_12 = approverChain.ca_approver_level_12; current.ca_approver_level_13 = approverChain.ca_approver_level_13; current.ca_approver_level_14 = approverChain.ca_approver_level_14; current.ca_approver_level_15 = approverChain.ca_approver_level_15; } else{ gs.addErrorMessage(errorMessageNOApproverChain); current.setAbortAction(true); } } } })(current, previous);
5.显示workflow
UI Action
// Show the workflow context in a new window function showWorkflowContext() { var url = new GlideURL('/context_workflow.do'); url.addParam('sysparm_stack', 'test'); url.addParam('sysparm_table', 'x_dchhl_dch_ca_ca_request'); url.addParam('sysparm_document', g_form.getUniqueValue()); g_navigation.open(url.getURL(), "_blank"); }
6.导出PDF文档
UI Action
// Show the workflow context in a new window function changeToExprotView() { var url = new GlideURL('/x_dchhl_dch_ca_ca_request.do'); url.addParam('sys_id', g_form.getUniqueValue()); //url.addParam('sys_id', current.sys_id); //url.addParam('sysparm_record_target', 'x_dchhl_dch_ca_ca_request'); url.addParam('sysparm_view', 'Export_view'); url.addParam('view_forced', 'true'); g_navigation.open(url.getURL()); }
7.Submit For Approval
UI Action
var type = 'KeSuLeiXing'; var newCAUtilClass = new DCH_CACN_UtilClass(); var maximumAmt = newCAUtilClass.getThresholdMaximun(type); if (currentTotalAmt > maximumAmt || currentTotalAmt == 0){ gs.addErrorMessage(errorMessageThreshold); haveError = true; } else{ current.ca_status = '2'; current.update(); }
8.关联页面参数
relationship
(function refineQuery(current, parent) { // Add your code here, such as current.addQuery(field, value); current.addQuery('u_dch_ap_request_number', parent.sys_id); //current.addQuery('u_dch_ap_request_number', parent.number); var type = current.addQuery('u_dch_ap_request_type', parent.u_dch_ap_type); type.addOrCondition('u_dch_ap_request_type', ''); var subType = current.addQuery('u_dch_ap_request_sub_type', parent.u_dch_ap_sub_type); subType.addOrCondition('u_dch_ap_request_sub_type', ''); // if(current.isNewRecord()){ // current.addQuery('u_dch_ap_request_type', parent.u_dch_ap_type); // current.addQuery('u_dch_ap_request_sub_type', parent.u_dch_ap_sub_type); // } })(current, parent);
9.Include Script库
var DCH_CACN_UtilClass = Class.create(); DCH_CACN_UtilClass.prototype = { initialize: function() { }, returnEmployeeInfo: function(currentUserId){ //var currentUserId = this.currentUser; var userInfo = []; //gs.Info('currentUserId: '+currentUserId); var employeeTable = new GlideRecord('x_dchhl_dch_ca_employee'); employeeTable.addQuery("ca_associated_user",currentUserId); employeeTable.query(); while(employeeTable._next()){ userInfo.push(employeeTable); } var employeeDetail = userInfo[0]; return employeeDetail; }, getUserId: function(employeeId){ var userId; var employeeTable = new GlideRecord('x_dchhl_dch_ca_employee'); employeeTable.addQuery("sys_id",employeeId); employeeTable.query(); while(employeeTable.next()){ //gs.info('User Id:' + employeeTable.ca_associated_user); userId = employeeTable.ca_associated_user; } //gs.info('Finalised User Id:' + employeeTable.ca_associated_user); return userId; }, getThresholdKeSu: function(type,currentAmt){ var thresholdList = []; var arr = []; var thresholdTable = new GlideRecord('x_dchhl_dch_ca_credit_limit'); thresholdTable.addQuery("brand_type",type); thresholdTable.addQuery("maximum_amount",">=",currentAmt); thresholdTable.orderByDesc("maximum_amount"); thresholdTable.query(); while(thresholdTable.next()){ thresholdList.push(thresholdTable); } var criteria = thresholdList[0].criteria_id; var gr = new GlideRecord('x_dchhl_dch_ca_approver_chain'); gr.addQuery("chain_id",criteria); gr.query(); while(gr.next()){ arr.push(gr); } var approver = arr[0].approver_level_1; return approver; }, getThreshold: function(type,totalAmt){ //gs.info('threshold:'+type+' - '+subType+' - '+totalAmt); var thresholdList = []; var thresholdTable = new GlideRecord('x_dchhl_dch_ca_credit_limit'); thresholdTable.addQuery("brand_type",type); thresholdTable.addQuery("maximum_amount",">=",totalAmt); thresholdTable.orderByDesc("maximum_amount"); thresholdTable.query(); //gs.info('thresholdTable:'+thresholdTable[0]); while(thresholdTable.next()){ thresholdList.push(thresholdTable); } //gs.info('return:'+thresholdList[0].u_dch_ap_type); var threshold = thresholdList[0]; //gs.info('Threshold Id:'+threshold.u_dch_ap_criteria_id +' - '+threshold.u_dch_ap_type+' - '+threshold.u_dch_ap_sub_type+' - '+threshold.u_dch_ap_maximum_amount); return threshold; }, //ssh start+ returnApproverChainKeSu : function(firstApproverId,thresholdId){ var approverChainList = []; var approverChain = new GlideRecord('x_dchhl_dch_ca_approver_chain'); approverChain.addQuery("approver_level_1",firstApproverId); //approverChain.addQuery("ca_belongs_to_the_company",company); approverChain.addQuery("criteria_id",thresholdId); approverChain.query(); while (approverChain.next()){ approverChainList.push(approverChain); } var approverChainRecord = approverChainList[0]; return approverChainRecord; }, //ssh end+ returnApproverChain : function(firstApproverId,company,thresholdId){ //returnApproverChain : function(firstApproverId,company,dept){ gs.info('retreiveApproverChain:'+ firstApproverId +'-'+ company +'-'+ thresholdId); var approverChainList = []; var approverChain = new GlideRecord('x_dchhl_dch_ca_approver_chain'); approverChain.addQuery("approver_level_1",firstApproverId); approverChain.addQuery("ca_belongs_to_the_company",company); approverChain.addQuery("criteria_id",thresholdId); approverChain.query(); while (approverChain.next()){ approverChainList.push(approverChain); } var approverChainRecord = approverChainList[0]; return approverChainRecord; }, getThresholdMaximun:function(type){ var thresholdList = []; var maximumAmt; var thresholdTable = new GlideRecord('x_dchhl_dch_ca_credit_limit'); thresholdTable.addQuery("brand_type",type); thresholdTable.orderBy("maximum_amount"); thresholdTable.query(); while(thresholdTable.next()){ thresholdList.push(thresholdTable); } maximumAmt = thresholdList[0].maximum_amount; //gs.info('Maximum Amount:'+thresholdList[0].u_dch_ap_maximum_amount); return maximumAmt; }, type: 'DCH_CACN_UtilClass' };