cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

OIR RuleAlgorithm Customization

Darrell
12-Amethyst

OIR RuleAlgorithm Customization

The OOTB RuleAlgorithms available in Windchill for object initialization do not include a string concatenator that allows whitespace. The OOTB com.ptc.windchill.enterprise.revisionControlled.server.impl.NumberGenerator algorithm will concatenate together strings and attribute values, but it trims whitespace. Using a few lines of code, I was able to create my own. It makes use of the StringJoiner class available in java 1.8+.

 

package ext.company;

import wt.rule.algorithm.RuleAlgorithm;
import wt.util.WTException;
import wt.inf.container.WTContainerRef;
import java.text.*;
import java.util.*;

public class customStringjoinerRuleSpace implements RuleAlgorithm {

	public Object calculate(Object args[], WTContainerRef container) throws WTException {
		StringJoiner name = new StringJoiner(" ");
		if (args!=null && args.length>0) {
			for (int i=0; i<args.length; i++) {
				if (args[i] != null) {
					name.add(args[i].toString());
				}
			}
		}
		return name.toString().trim();
	}
}

Some info about creating rulealgorithms is available in this PTC Tech Support article: .

To make use of the new custom algorithm, compile the code into the class file and place it into the codebase folder that matches the package name, e.g. <WT_Home>/codebase/ext/company. Then, the OIR can be modified to make use of the new custom algorithm. For example, if I want to have the name attribute be the concatenation of the title attribute value and the text "PROC", the name section of the OIR would read:

 

               <!-- set the Name to be autogenerated from title + "PROC"-->
               <AttrValue id="name" algorithm="ext.company.customStringjoinerRuleSpace">
			<Attr id="Title"/>
<Arg>PROC</Arg> </AttrValue>

 The Attr and Arg tag values are passed to the customStringjoinerRuleSpace code as args.

 

As is usually the case with Windchill, in order to make changes to the customStringjoinerRuleSpace code after it has been used, you must restart Windchill.

1 REPLY 1
Darrell
12-Amethyst
(To:Darrell)

I still can't edit blog articles after posting, so I'll add this as a comment. Some info about creating rulealgorithms is available in this PTC Tech Support article: CS110198.

Top Tags