Skip to main content
12-Amethyst
April 29, 2026
Solved

Rename Change Tasks programmatically after Change Notice is created

  • April 29, 2026
  • 2 replies
  • 39 views

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)
...

 

Best answer by avillanueva

Yep, you cannot use that modify method. Use IdentityHelper.service.changeIdentity.

2 replies

avillanueva
23-Emerald I
23-Emerald I
April 30, 2026

Try using the code block when pasting in code or error messages. Its renders poorly like above and is impossible to read. I use a robot to rename/renumber the CR from the CN to match so I know this works. Here is my workflow block. It has a validation check to catch any errors, routing them to an admin for inspection. Rare but its a good practice for odd issues so workflow does not stall.

Here is the part of the expression that does the rename/renumber on the CR:

 //Perform renumber to CN and associated CR
WTChangeOrder2MasterIdentity ecnID = WTChangeOrder2MasterIdentity.newWTChangeOrder2MasterIdentity((WTChangeOrder2Master)ec.getMaster());
for(QueryResult queryresult = ChangeHelper2.service.getChangeRequest(ec, true); queryresult.hasMoreElements();)
{
WTChangeRequest2 ecr = (wt.change2.WTChangeRequest2)queryresult.nextElement();
WTChangeRequest2MasterIdentity ecrID = WTChangeRequest2MasterIdentity.newWTChangeRequest2MasterIdentity((WTChangeRequest2Master)ecr.getMaster());
LOGGER.debug("CN:"+ecnID.getNumber());
LOGGER.debug("CR:"+ecrID.getNumber());
LOGGER.debug("Changing to " + newECNumber);
ecnID.setNumber(newECNumber);
ecrID.setNumber(newECNumber);
IdentityHelper.service.changeIdentity((WTChangeRequest2Master)ecr.getMaster(),ecrID);
IdentityHelper.service.changeIdentity((WTChangeOrder2Master)ec.getMaster(),ecnID);
}

You want to handle exceptions like WTPropertyVetoException, WTException and NumberFormatException.

12-Amethyst
April 30, 2026

Thanks for the feedback. I will take a look.
And thanks for the code block suggestion. This was posted from the PTC support call logger, so I couldn’t control the format. And once it was posted it doesn’t seem that you can edit it to correct the format. (Hopefully that will be possible in the future.)

AndrewK
Community Manager
April 30, 2026

Hi ​@jfrankovich, you can edit your post but there is a one-hour time limit. I cleaned the code up in your post, and I will look into making improvements on the support side. Thanks for the feedback!

12-Amethyst
April 30, 2026
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);
}

 

avillanueva
23-Emerald I
23-Emerald I
April 30, 2026

Yep, you cannot use that modify method. Use IdentityHelper.service.changeIdentity.