基础管理 > 支持协作 > 工作流管理 > 工作流工具 > 工作流模板管理 > 工作流代码示例 > 执行表达式自动机示例 > PBO 属性用作工作流变量 > 使用工作流变量 (Set) 修改属性
  
使用工作流变量 (Set) 修改属性
本主题提供了使用工作流变量和“执行表达式”自动机节点修改主要业务对象属性的示例。参与者所修改的对象是为其分配的任务主题时,如果该参与者没有直接修改权限,那么这将非常有用。
说明
PersistableAdapter API 用于根据已分配活动的工作流变量获取和设置 PBO 属性值。工作流变量值衍生自任务中的用户输入。
说明
使用以下高级步骤:
1. 在工作流模板中,创建一个或多个进程级变量。这些变量代表要修改的 PBO 属性。选择整数、布尔值或 java.lang.string 的“类型名称”(数据类型)。确保这些变量可见且可重置。
有关进程特性 (包括变量) 的详细信息,请参阅“变量”选项卡定义工作流变量
2. 在所分配任务的活动节点的“变量”选项卡中,创建初始化自进程级变量 (在上一步中创建) 的活动变量,并将其复制到进程级变量。这些变量用于获取用户输入,以从中得到随后要复制到进程级变量的值。
3. 创建执行表达式自动机。在“表达式”选项卡中,输入用于通过工作流变量更新 PBO 属性的代码,其值可从所分配活动中的用户输入获得。有关表达式代码示例,请参阅下节。
表达式代码示例
在下文所示的代码示例中,共有四种为以下内部名称 (如“类型管理器”中所示)、变量名称及数据类型的变量:
属性内部名称
工作流变量名称
数据类型
StringAttribute
StringAttributeVariable
java.lang.String
BooleanAttribute
BooleanAttributeVariable
布尔型
DateAttribute
DateAttributeVariable
java.lang.String
IntegerAttribute
IntegerAttributeVariable
int
* 
以下示例还提供了有关如何格式化字符串数据类型的 DateAttribute 值的说明。
wt.part.WTPart part = (wt.part.WTPart)primaryBusinessObject;
//Get check out folder for the current user in the session
wt.folder.Folder checkoutFolder = wt.vc.wip.WorkInProgressHelper.service.getCheckoutFolder();
//Check out object
wt.vc.wip.CheckoutLink chklink = wt.vc.wip.WorkInProgressHelper.service.checkout(part, checkoutFolder, "Check out comment");
wt.part.WTPart wrk = (wt.part.WTPart) chklink.getWorkingCopy();
System.out.println("\nChecked out WTPart ......"+wrk.getName()+"\t"+wrk.getCheckoutInfo());
com.ptc.core.lwc.server.PersistableAdapter pbo = new com.ptc.core.lwc.server.PersistableAdapter(wrk, null, null, null);
System.out.println("\nGot pbo...."+pbo.toString());
pbo.load("StringAttribute","BooleanAttribute","DateAttribute","IntegerAttribute");
System.out.println("Loading Attributes");
System.out.println("StringAttribute : "+pbo.get("StringAttribute"));
System.out.println("BooleanAttribute : "+pbo.get("BooleanAttribute"));
System.out.println("DateAttribute : "+pbo.get("DateAttribute"));
System.out.println("IntegerAttribute : "+pbo.get("IntegerAttribute"));
pbo.set("StringAttribute", StringAttributeVariable);
pbo.set("BooleanAttribute", BooleanAttributeVariable);
pbo.set("IntegerAttribute", new java.lang.Long(IntegerAttributeVariable));
//Date attribute is more complex
java.text.DateFormat df = java.text.DateFormat.getDateInstance(java.text.DateFormat SHORT);
String tempDate= DateAttributeVariable;
java.util.Date objectDate = df.parse(tempDate);
pbo.set("DateAttribute", new java.sql.timestamp(objectDate.gettime()));

wt.fc.Persistable p = pbo.apply();
//Modify attributes
wt.fc.PersistenceHelper manager.modify(p);
try
{
// Check in object
wt.vc.wip.WorkInProgressHelper.service.checkin((wt.vc.wip.Workable) p, "Check in comment");
}
catch (wt.util.WTException e)
{
e.printStackStrace();
}
catch (wt.util.WTPropertyVetoException e)
{
e.printStackTrace();
}