Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X
If Number is E-M030002 them remove E- after it goes to certain lifecycle state
Solved! Go to Solution.
Hi @MP_10719580
Here is example from WF Activity how to set number activity to a format "CN+/+AtivityNumber"
wt.fc.Identified master = (wt.fc.Identified)thisActivity.getMaster();
wt.change2.WTChangeActivity2MasterIdentity identity = (wt.change2.WTChangeActivity2MasterIdentity) master.getIdentificationObject();
identity.setNumber(setNumber);
wt.fc.IdentityHelper.service.changeIdentity(master,identity);
wt.fc.PersistenceHelper.manager.refresh(thisActivity);
PetrH
Hi @MP_10719580
Set the Lifecycle template to advanced and run own workflow in the state where you need.
Place an expresion robot with code in the workflow.
Write code to change the number in the WF .
PetrH
Can you give some references or examples?
Hi @MP_10719580
Here is example from WF Activity how to set number activity to a format "CN+/+AtivityNumber"
wt.fc.Identified master = (wt.fc.Identified)thisActivity.getMaster();
wt.change2.WTChangeActivity2MasterIdentity identity = (wt.change2.WTChangeActivity2MasterIdentity) master.getIdentificationObject();
identity.setNumber(setNumber);
wt.fc.IdentityHelper.service.changeIdentity(master,identity);
wt.fc.PersistenceHelper.manager.refresh(thisActivity);
PetrH
I try to change part number by workflow, but I gives error that cannot change number.
Hi @MP_10719580
Where do you place the code?
You need to save the object and after the object is stored in database you can change the number.
This is common error, if you put the code as a first node in workflow, and the WF is run before object is stored.
You have to use wait or something that the store operation is done succesfully
PetrH
Thanks for give solution, now it's working.
Sounds similar to this: https://www.ptc.com/en/support/article/CS315688?source=search
Can we see or you check your OIR for the Part object? Is number auto-generated and immutable?
Other notes:
https://www.ptc.com/en/support/article/CS110835?source=search
That one does not make sense since we are not changing the number in an edit window.
Hi @avillanueva
Good point with the OIR constrain number immutable.
with the wt.fc.IdentityHelper.service.changeIdentity(master,identity); there should not be any issue if it is done by workflow and under admin.
PetrH
There is also a way to do a forced switch to admin within a workflow/code. I use it when I work with Identity changes:
SessionContext previousContext = null;
boolean enforced = false;
// Switch to admin
enforced = SessionServerHelper.manager.setAccessEnforced(false);
previousContext = SessionContext.newContext();
SessionHelper.manager.setAdministrator();
// Do the change
// Switch back
SessionContext.setContext(previousContext);
SessionServerHelper.manager.setAccessEnforced(enforced);
previousContext = null;
enforced = false;
Kind regards,
Dmitry