基本的な管理機能 > コラボレーションのサポート > ワークフロー管理 > ワークフローツール > ワークフローテンプレート管理 > ワークフローのコーディング例 > 定義式実行ロボットの例 > ワークフロー変数としての PBO 属性 > ワークフロー変数による属性の修正 (Set)
  
ワークフロー変数による属性の修正 (Set)
このトピックでは、ワークフロー変数と定義式実行ロボットノードを使用して、プライマリビジネスオブジェクトの属性を修正する例を説明します。これは、参加者が、自分に割り当てられたタスクの対象となるオブジェクトを直接修正する権限を持たない場合に役立ちます。
説明
PersistableAdapter API を使用すると、割り当てられたアクティビティのワークフロー変数に基づいて、プライマリビジネスオブジェクト属性の値を取得および設定できます。ワークフロー変数の値は、タスク内でユーザー入力から設定されます。
指示
次の詳細な手順を使用します。
1. ワークフローテンプレートで、プロセスレベルの変数を 1 つ以上作成します。これらの変数は、修正するプライマリビジネスオブジェクト属性を表します。「タイプ名」(データタイプ) で、「int」、「boolean」、または「java.lang.string」を選択します。変数の「表示」および「リセット可能」が有効であることを確認します。
変数などのプロセスプロパティの詳細については、「変数」タブおよびワークフロー変数の定義を参照してください。
2. 割り当てられたタスクで、アクティビティノードの「変数」タブに移動し、アクティビティ変数を作成して、起動ポイントとコピー先を前のステップで作成したプロセスレベル変数に設定します。これらの変数を使用して、ユーザー入力から値を取得し、取得した値をプロセスレベル変数にコピーします。
3. 定義式実行ロボットを作成します。「定義式」タブで、ワークフロー変数によってプライマリビジネスオブジェクト属性を更新するコードを入力します。ワークフロー変数には、割当アクティビティのユーザー入力から取得した値が設定されています。定義式のコード例については、次のセクションを参照してください。
定義式のコード例
次のコード例では、次の内部名 (「タイプマネージャ」に表示)、変数名、データタイプを持つ 4 つの変数が示されています。
属性の内部名
ワークフローの変数名
データタイプ
StringAttribute
StringAttributeVariable
java.lang.String
BooleanAttribute
BooleanAttributeVariable
boolean
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();
}