Skip to main content
5-Regular Member
January 21, 2026
Solved

在 Windchill 中驳回工作流任务时,需要验证 "备注" 字段不为空;通过工作流任务时,不验证 "备注" 字段是否为空;怎么配置

  • January 21, 2026
  • 2 replies
  • 356 views

在 Windchill 中驳回工作流任务时,需要验证 "备注" 字段不为空;通过工作流任务时,不验证 "备注" 字段是否为空;怎么配置

Best answer by TDT

Hi @QS_10834211,

 

Did you follow Step 3 in article CS150969?

If you have done so, please try adding some alerts in the JavaScript function and check where it is breaking.

2 replies

16-Pearl
January 21, 2026
13-Aquamarine
January 21, 2026
<objecttype name="work" class="wt.workflow.work.WorkItem">
		<action name="complete" enabledwhensuspended="true" ajax="page">
			<command class="ext.workitem.work.CustNmWorkItemCommands"
				method="complete" onClick="customWorkitemCompleteOnClick()" />
		</action>
</objecttype>
<script type="text/javascript" language="javascript" charset="utf-8">
		function customWorkitemCompleteOnClick(){
 return customWorkitemCompleteValidator();
 }
 
 function customGetWorkitemComment(){
 var inputs = document.getElementsByTagName("input");
			for(var i in inputs){
				var input = inputs[i];
				if(input.type=='radio'){
					if(input.checked){
					console.log(input.value);
						if(input.value=='\u9a73\u56de'){//if Chinese is used, it will be garbled
							if( (document.getElementById("workitem_comment").value == "") || (document.getElementById("workitem_comment").length == 0)){
								return false;
							}else{
								return true;
							}
						}
					}
				}
			}
			return true;
			
 }

 function customWorkitemCompleteValidator(){
 var result = true; // if returned result is false, the task form will stay opened
 var comment = customGetWorkitemComment();
 result=comment;

 if(result){
 result = EnableTextBox(); // call ootb onClick handler
 }else{
 alert("\u5ba1\u6279\u610f\u89c1\u4e0d\u80fd\u4e3a\u7a7a");
 }
 return result; 
 }
</script>

javascript代码放到netmarkets/jsp/util/begin_custom.jspf中,然后要修改完成任务的action,对于中文提示,要用unicode编码下才可以正常显示。

5-Regular Member
January 23, 2026

Hi Professor

代码已经放到netmarkets/jsp/util/begin_custom.jspf

代码:

function customWorkitemCompleteOnClick(){ return customWorkitemCompleteValidator(); } function customGetWorkitemComment(){ var inputs = document.getElementsByTagName("input"); for(var i in inputs){ var input = inputs[i]; if(input.type=='radio'){ if(input.checked){ console.log(input.value); if(input.value=='驳回'){//if Chinese is used, it will be garbled if( (document.getElementById("workitem_comment").value == "") || (document.getElementById("workitem_comment").length == 0)){ return false; }else{ return true; } } } } } return true; } function customWorkitemCompleteValidator(){ var result = true; // if returned result is false, the task form will stay opened var comment = customGetWorkitemComment(); result=comment; if(result){ result = EnableTextBox(); // call ootb onClick handler }else{ alert("审批意见不能为空"); } return result; }

但是没有生效,不知道什么原因;

你说的“要修改完成任务的action”,是怎么改?

Qihao.Shang

PLM Engineer

16-Pearl
January 23, 2026

Hi @QS_10834211,

Have you added the following entry to custom-actions.xml?

<objecttype name="work" class="wt.workflow.work.WorkItem">
 <action name="complete" enabledwhensuspended="true" ajax="page">
 <command class="com.ptc.netmarkets.work.NmWorkItemCommands" method="complete" onClick="validateComments()"/> 
 </action> 
</objecttype>