Modifying Attributes With Workflow Variables (Set)
This topic provides a sample of using workflow variables and the Execute Expression robot node to modify an attribute of a primary business object. This is helpful if the participant does not have permissions to directly modify the object that is the subject of a task assigned to them.
Description
The PersistableAdapter API is used to get and set the PBO attribute value based on the workflow variable of an assigned activity. The workflow variable value is derived from user input in a task.
Instructions
The following high-level procedure is used:
1. In a workflow template, create one or more process-level variables. These variables represent the PBO attributes you want to modify. Select a Type Name (data type) of int, boolean, or java.lang.string. Make sure the variables are Visible and Resetable.
For more information about process properties, including variables, see Variables Tab and Defining Workflow Variables.
2. In the Variables tab of the activity node for the assigned task, create activity variables that initialize from, and copy into the process-level variables you created in the previous step. These variables are used to get user input to acquire values that are then copied into the process-level variables.
3. Create an Execute Expression robot. In the Expression tab, enter the code that updates the PBO attributes with the workflow variable, the values of which were obtained by user input on the assigned activity. See the following section for an expression code example.
Expression Code Example
In the code example that follows, there are four variables with the following internal names (as shown in the Type Manager), variable names, and data types:
Attribute Internal Name
Workflow Variable Name
Data Type
StringAttribute
StringAttributeVariable
java.lang.String
BooleanAttribute
BooleanAttributeVariable
boolean
DateAttribute
DateAttributeVariable
java.lang.String
IntegerAttribute
IntegerAttributeVariable
int
* 
The following example also provides instructions on how to format the DateAttribute value from a string data type.
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();
}
Was this helpful?