基础管理 > 支持协作 > 工作流管理 > 工作流工具 > 工作流模板管理 > 工作流代码示例 > 执行表达式自动机示例 > PBO 属性用作工作流变量 > 在路由选择表达式 (Get) 中检索属性
  
在路由选择表达式 (Get) 中检索属性
您可以使用 PersistableAdapter API Get 方法来检索要在路由工作流模板中使用的属性值。以下示例从主要业务对象中检索属性值,并将这些属性值用于路由工作流模板 Or 连接器节点的路由选择表达式。
说明
PersistableAdapter API 检索要在已分配活动的工作流变量中使用的 PBO 属性值。
说明
使用以下步骤:
1. 添加一个“或”连接器节点。
2. 在连接器特性中,指定以下内容:
a. “路由选择类型”下,选择“条件”
b. “路由选择事件”字段中,输入一个或多个自定义事件的名称 (包括单独行中的多个条目)。
c. “路由/计数表达式”字段中,输入根据 PBO 属性值选择路由选择事件的路由选择表达式代码。单击“检查语法”,确保表达式的语法正确。有关路由选择表达式代码示例,请参阅下节。
d. 单击“确定”关闭“条件特性”窗口。
3. 为每个路由选择事件创建活动节点。
4. 为每个路由选择事件创建将条件节点链接到关联的活动节点的进程链接。在进程链接特性中,指定“条件中的事件”下方适用路由选择事件旁的“开始”操作。
5. 根据需要结束工作流模板。
路由选择表达式代码示例
在下面的代码示例中,根据四个 PBO 属性的值,提供了四个路由选择事件。表达式使用 PersistableAdapter API 获取 PBO 属性的值。之后,每个值都会转换成将在表达式中计算的变量,以便选择路由选择事件。下表列出了 PBO 属性内部名称 (如“类型管理器”中所示)、变量名称、数据类型和每个属性的关联路由选择事件:
属性内部名称
工作流变量名称
数据类型
关联的路由选择事件
StringAttribute
stringVar
java.lang.String
StringMatch
BooleanAttribute
booleanVar
布尔型
BooleanMatch
DateAttribute
dateVar
java.lang.String
DateMatch
IntegerAttribute
integerVar
int
IntegerMatch
* 
请注意下例中将 DateAttribute 值从字符串数据类型格式化为日期格式的代码。
wt.part.WTPart part = (wt.part.WTPart)primaryBusinessObject;
com.ptc.core.lwc.server.PersistableAdapter obj = new
com.ptc.core.lwc.server.PersistableAdapter(part,null,null,null);
obj.load("BooleanAttribute","DateAttribute","IntegerAttribute","StringAttribute");
// Retriving Boolean Attribute
Boolean booleanVar = (boolean)obj.get ("BooleanAttribute");
System.out.println("booleanVar = "+booleanVar);
// Retriving String Attribute
String stringVar = (String) obj.get ("StringAttribute");
System.out.println("stringVar = "+stringVar);
// Retriving Integer Attribute
Long integerVar = new java.lang.Long ((java.lang.Long)obj.get ("IntegerAttribute"));
System.out.println("integerVar = "+integerVar);
// Retriving Date Attribute
java.text.DateFormat df = java.text.DateFormat.getDateInstance(java.text.DateFormat.SHORT);
java.sql.Timestamp tempDate = (java.sql.Timestamp)obj.get ("DateAttribute");
java.util.Date dateVar = new java.util.Date(tempDate.getTime());
System.out.println("dateVar = "+dateVar);
java.util.Date today = new java.util.Date();
System.out.println("today = "+today );
if (booleanVar)
{
result="BooleanMatch";
System.out.println("result = "+result);
}
else if(today.compareTo(dateVar) == 0)
{
result = "DateMatch";
System.out.println("result = "+result);
}
else if (integerVar == 123)
{
result= "IntegerMatch";
System.out.println("result = "+result);
}
else if (stringVar.equalsIgnoreCase ("test"))
{
result = "StringMatch";
System.out.println("result = "+result);
}