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

Community email notifications are disrupted. While we are working to resolve, please check on your favorite boards regularly to keep up with your conversations and new topics.

Playing with PersistableAdapter

grocha
1-Newbie

Playing with PersistableAdapter

I am starting to play with the new "PersistableAdapter" API, I am noob to java too.


My question is, how to update an attribute of the primaryBusinessObject using a workflow expression or transition?


If I try the code below directly I will receive an error cause the PBO was not checked out before running the code, but If I checkout the PBO before running it I receive the error stating that "1.1 is the original version of a working copy and cannot be modified"


Obviously I am missing something here... Any help?



com.ptc.core.lwc.server.PersistableAdapter obj = new com.ptc.core.lwc.server.PersistableAdapter(primaryBusinessObject,null,null,new com.ptc.core.meta.common.UpdateOperationIdentifier());




newValue);


obj.persist();


"A goal without a plan is just a wish."

3 REPLIES 3
rhegde
1-Newbie
(To:grocha)

Try the following:

- Check out the object
- Get the "working copy" of primary business object and pass it to the
method (PersistableAdapter)

- Check in the object once you modify your object


*Note:*

- You can use
"wt.sandbox.SandboxHelper.service.getWorkingCopyOf((wt.vc.Versioned)primaryBusinessObject)"
to get working copy of primary business object. Based on my knowledge
"getWorkingCopy" API is deprecated in 10.X

- Alternately, check if you can use class "WorkInProgressHelper" to get
working copy.


--
Rochan Hegde
Productspace Solutions Inc.
Cell: 630-495-2999 x 8121


*Follow us at
*Join Windchill360 at:

Windchill360.com
> java too.
>
> My question is, how to update an attribute of the primaryBusinessObject
> using a workflow expression or transition?
>
> If I try the code below directly I will receive an error cause the PBO was
> not checked out before running the code, but If I checkout the PBO before
> running it I rece...





























This may be what you are looking for. Use this class instead. I vaguely remember that there may be an even newer class for this in 10.2 but you'd have to look at the Java doc's for that info. I've used this a lot in workflows. Works really well and doesn't require any checkout.

I guess there is a new class that helps us do this. I've done this in the past with a custom webject but this is so much nicer. I haven't used it yet but it is from PTC's documentation on the API.



[Description: extended by] com.ptc.core.lwc.server.LWCNormalizedObject
grocha
1-Newbie
(To:grocha)

Just for reference of others with the same need, the code for updating an
attribute in a workflow expression/transition using version 10.2 is:



Object object=primaryBusinessObject;

if(object.getClass().isAssignableFrom(wt.doc.WTDocument.class)){

wt.doc.WTDocument doc=(wt.doc.WTDocument)primaryBusinessObject;

doc = (wt.doc.WTDocument)
wt.vc.wip.WorkInProgressHelper.service.checkout(doc,wt.vc.wip.WorkInProgress
Helper.service.getCheckoutFolder(), ").getWorkingCopy();

com.ptc.core.lwc.server.PersistableAdapter obj = new
com.ptc.core.lwc.server.PersistableAdapter(doc,null,java.util.Locale.getDefa
ult(),new com.ptc.core.meta.common.UpdateOperationIdentifier());

obj.load("Attr1");

obj.set("Attr1", "NEW VALUE");

doc=(wt.doc.WTDocument)obj.apply();

wt.fc.PersistenceHelper.manager.modify(doc);

wt.vc.wip.WorkInProgressHelper.service.checkin(doc, null);

}





Estou a disposição para qualquer esclarecimento.






Top Tags