Rename Change Tasks programmatically after Change Notice is created
I am using Windchill PDMLink Release 12.1 and Datecode with CPS 12.1.2.14
When we create the Implementation Plan for our Change Notices, our Change Admins manually prepend the number of the CN to the Change Task Name field for the convenience of our users (when looking at their My Tasks tables). We would like to automate this process since it is time consuming for the admins. I have attempted to write code to do this automatically, but it seems that the API does not allow this after the object is persisted. I would like to understand why this is possible manually but does not appear to work programmatically. I see the Name field in the CA Master table but don't see an alternate "name" in the CA iteration table. Perhaps I am just approaching it wrong in my code.
Code:
wt.change2.WTChangeActivity2 ca = (wt.change2.WTChangeActivity2) primaryBusinessObject;
// Get parent Change Notice
wt.change2.WTChangeOrder2 cn = (wt.change2.WTChangeOrder2) wt.change2.ChangeHelper2.service.getChangeOrder(ca);
String cnNumber = cn.getNumber();
String originalName = ca.getName();
String newName = originalName;
// 1. If the name already starts with the CN number, do nothing
if (!originalName.startsWith(cnNumber)) {
// 2. Replace placeholder if present
if (originalName.contains("{CN}")) {
newName = originalName.replace("{CN}", cnNumber);
}
// 3. Otherwise prepend
else {
newName = cnNumber + " " + originalName;
}
// Apply the rename
ca.setName(newName);
wt.fc.PersistenceHelper.manager.modify(ca);
}
Error
wt.util.WTException: Changes to "Name" are restricted, once the object has been persisted.
Nested exception:
wt.util.WTPropertyVetoException: Changes to "Name" are restricted, once the object has been persisted.
wt.workflow.engine.FailedExpressionException: ...
at wt.change2._ChangeActivity2Master.nameValidate(_ChangeActivity2Master.java:37)
at wt.change2._ChangeActivity2Master.setName(_ChangeActivity2Master.java:32)
at wt.change2._WTChangeActivity2.setName(_WTChangeActivity2.java:134)
at wt.workflow.expr.WfExpression467462.executemethod_1(WfExpression467462.java:65)
...

