cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

How Reload part number after lifecycle state change?

MP_10719580
6-Contributor

How Reload part number after lifecycle state change?

If Number is E-M030002 them remove E- after it goes to certain lifecycle  state

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @MP_10719580 

Here is example from WF Activity how to set number activity to a format "CN+/+AtivityNumber" 

HelesicPetr_1-1702305470159.png

 

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

 

View solution in original post

9 REPLIES 9

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" 

HelesicPetr_1-1702305470159.png

 

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

 

Capture24.PNG

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.

avillanueva
22-Sapphire II
(To:MP_10719580)

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

Top Tags