Community Tip - You can change your system assigned username to something more personal in your community settings. X
I have a set of WTParts whose serial number effectivity value has been entered wrong. I want to delete them using API.
What is the API to access the serial number effectivities associated with WTPart?
I know that I can delete the serial numbers using the following API:
PersistenceHelper.manager.delete((ProductSerialNumberEffectivity) serial);
But I am having trouble getting the ProductSerialNumberEffectivity for a particular WTPart.
Please help.
Thanks in advance
You may want to try this. I used this way back and sharing for your reference as it is. So you may need to modify and test it as per your business use case.
QueryResult qr2 = wt.effectivity.EffectivityHelper.service.getEffectivities(prt); // Object of WTPart whose effectivity you want to delete...
while (qr2.hasMoreElements()) {
Object obj = (Object) qr2.nextElement();
System.out.println("Object-> " + obj.toString());
if (obj.getClass().isAssignableFrom(wt.part.ProductSerialNumberEffectivity.class))
{
System.out.println( " Found Serial Numbered Effectivity" );
wt.part.ProductSerialNumberEffectivity serial = (wt.part.ProductSerialNumberEffectivity)obj;
String sRange=serial.getRange().getStart().toString().trim();
System.out.println("Start Range is --->"+sRange);
if (serial.getRange().getEnd().toString().trim() != null)
{
sRange += " - " + serial.getRange().getEnd().toString().trim();
}
else
{
sRange += " - " + "<open>";
}
// System.out.println(" Range: " + sRange);
// System.out.println(" Effectivity Type: " + serial.getEffContext());
System.out.println("*** Trying to delete Serial Effectivity ***");
PersistenceHelper.manager.delete(serial); // be careful here. Your deleting something....
System.out.println("*** SerialNumbered Effectivity for WTPart: "+prt.getNumber()+" is succesfully deleted ***");
}
else
{
System.out.println( "Effectivity other than Serial..." );
}
}
I hope this helps you.
Regards,
Shirish
Hi Shirish
I tried this code - I am faced with another unusual problem. I notice that the EffectivityHelper.service.getEffectivities(prt); API retrieves only WTDatedEffectivity objects, that is, according to your code I always get "Effectivity other than serial" printing in the console.
I thought the API was meant for date effectivity only, until I wrote a query to retrieve all serial number effectivity (just to check) using the following query:
QuerySpec qs = new QuerySpec(wt.part.ProductSerialNumberEffectivity.class)
QueryResult qr = PersistenceHelper.manager.find(qs);
This gave me a null result. I have several WTParts with serial number effectivities associated with them - I can see them in the Service Effectivity UI as well. But, for some reason, I am unable to retrieve them using API.
What could be the reason for this?