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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

How to use modify the value of attribute in a workflow depending on whether the activity is completed or not?

prathi
12-Amethyst

How to use modify the value of attribute in a workflow depending on whether the activity is completed or not?

I am creating a workflow with one activity. If that activity is completed, then the value of the IBA (Material_Type) must be changed from whatever the user has entered to value defined here (Copper).

I tried the following codes but still did not get the result. please help me to solve this.

1.

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

obj.load("Material_Type");

obj.set("Material_Type", "Copper");

obj.apply();

2.

object = (wt.fc.WTObject)

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

obj.load("Material_Type");

obj.set("Material_Type", "Copper");

obj.apply();

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

3.

wt.fc.QueryResult qr = wt.part.WTPart(primaryBusinessObject);

while (qr.hasMoreElements())

{

wt.fc.Persistable my_persistable = (wt.fc.Persistable)qr.nextElement();

my_persistable = wt.vc.wip.WorkInProgressHelper.service.checkout( (wt.vc.wip.Workable) my_persistable, wt.vc.wip.WorkInProgressHelper.service.getCheckoutFolder(),"").getWorkingCopy();

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

obj.load("Material_Type");

obj.set("Material_Type", "Copper");

obj.apply();

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

wt.vc.wip.WorkInProgressHelper.service.checkin((wt.vc.wip.Workable) my_persistable,"");

}

ACCEPTED SOLUTION

Accepted Solutions
satre-2
12-Amethyst
(To:prathi)

You can add below code in Activity's complete transition. to update the attribute value

wt.part.WTPart part = ( wt.part.WTPart) primaryBusinessObject;

  wt.folder.Folder checkoutFolder = wt.vc.wip.WorkInProgressHelper.service.getCheckoutFolder();

  wt.vc.wip.CheckoutLink checkout = wt.vc.wip.WorkInProgressHelper.service.checkout(part, checkoutFolder,

  null);

  wt.fc.Persistable my_persistable = checkout.getWorkingCopy();

  com.ptc.core.lwc.server.LWCNormalizedObject obj = new com.ptc.core.lwc.server.LWCNormalizedObject(

  my_persistable, null, java.util.Locale.ENGLISH, null);

  obj.load("Material_Type");

  obj.set("Material_Type", "Copper");

obj.apply();

  wt.fc.PersistenceHelper.manager.save(my_persistable);

  wt.vc.wip.WorkInProgressHelper.service.checkin(part, "Updated By Workflow");

let me know if it works

Thanks

Shreyas

View solution in original post

2 REPLIES 2
satre-2
12-Amethyst
(To:prathi)

You can add below code in Activity's complete transition. to update the attribute value

wt.part.WTPart part = ( wt.part.WTPart) primaryBusinessObject;

  wt.folder.Folder checkoutFolder = wt.vc.wip.WorkInProgressHelper.service.getCheckoutFolder();

  wt.vc.wip.CheckoutLink checkout = wt.vc.wip.WorkInProgressHelper.service.checkout(part, checkoutFolder,

  null);

  wt.fc.Persistable my_persistable = checkout.getWorkingCopy();

  com.ptc.core.lwc.server.LWCNormalizedObject obj = new com.ptc.core.lwc.server.LWCNormalizedObject(

  my_persistable, null, java.util.Locale.ENGLISH, null);

  obj.load("Material_Type");

  obj.set("Material_Type", "Copper");

obj.apply();

  wt.fc.PersistenceHelper.manager.save(my_persistable);

  wt.vc.wip.WorkInProgressHelper.service.checkin(part, "Updated By Workflow");

let me know if it works

Thanks

Shreyas

prathi
12-Amethyst
(To:satre-2)

Hey Shreyas,

It worked. Thanks a lot.

Even after trying various permutations and combinations in the codes, i couldn't get it.

I just request you to explain me what did you do? (If possible line by line). I am a fresher and relatively new to Windchill. This would help me to hone my skills.

Regards,

Prasad

(Prasad.Rathi@itcinfotech.com)

Announcements


Top Tags