How to update quantity attribute of Part Structure through api.
Hello Rakesh Kumar,
You can try below code snippet:
public class UpdateLineNumber implements RemoteAccess
{
public static void main (String a[]) throws WTException, WTPropertyVetoException, RemoteException, InvocationTargetException
{
RemoteMethodServer rms = RemoteMethodServer.getDefault();
rms.setUserName("wcadmin");
rms.setPassword("ts");
Class[] arg_type = {};
Object[] ar = {};
rms.invoke("updateLineNumberUS37", "ext.UpdateLineNumber", null, arg_type, ar);
}
public static void updateLineNumberUS37() throws WTException, WTPropertyVetoException, IOException
{
String partOid = "VR:wt.part.WTPart:657087";
ReferenceFactory rf = new ReferenceFactory();
WTReference obj = (WTReference) rf.getReference(partOid);
WTPart part = (WTPart)obj.getObject();
CheckoutLink col = WorkInProgressHelper.service.checkout(part, (Folder)WorkInProgressHelper.service.getCheckoutFolder(), "MG");
WTPart prt =(WTPart)col.getWorkingCopy();
QueryResult qr = wt.part.WTPartHelper.service.getUsesWTPartMasters(prt);
while(qr.hasMoreElements())
{
WTPartUsageLink ul = (WTPartUsageLink)qr.nextElement();
Quantity q = new Quantity();
double quantity = 12;
q.setAmount(quantity);
ul.setQuantity(q);
PersistenceServerHelper.manager.update(ul);
PersistenceHelper.manager.save(prt);
}
// Check in part
WorkInProgressHelper.service.checkin(prt,"cc") ;
System.out.println("\n finihsed");
}
}
I hope this helps you.
Regards,
Shirish
Hi Shirish
Thanks for the help.
//Rakesh