Solution
An example of While/Select statements to find InventSerials, when Works Order is known. Here I also will use a chance to note the ListEnumerator. No Joins are used in this example.
An example of achieving same result using Queries.
Class declaration
public class YourClass
{
InventTransOrigin inventTransOrigin;
InventTrans inventTrans;
InventDim inventDim;
InventSerial inventSerial;
int64 recId;
str transId;
List recIds;
List dimIds;
List inventSerialIds;
ListEnumerator enumerator;
}
Methods
public void getInventSerials()
{
this.getRecId_InventTransId("DON1-000034", InventTransType::Production);
this.getInventDimIds();
this.getInventSerialIds();
}
public void getRecId_InventTransId(InventRefId _inventRefId, InventTransType _inventTransType)
{
recIds = new List(Types::String);
try
{
while select RecId, InventTransId
from inventTransOrigin
where inventTransOrigin.ReferenceId == _inventRefId &&
inventTransOrigin.ReferenceCategory == _inventTransType
{
recId = inventTransOrigin.RecId;
transId = inventTransOrigin.InventTransId;
info(strFmt("RecId: %1, InventTransId: %2", int642str(inventTransOrigin.RecId), inventTransOrigin.InventTransId));
}
}
catch(Exception::error)
{
error("There was an error getting the record.");
}
}
public List getInventDimIds()
{
dimIds = new List(Types::String);
try
{
while select InventDimId
from inventTrans
where inventTrans.InventTransOrigin == recId
{
dimIds.addEnd(inventTrans.inventDimId);
info(strFmt("InventDimId: %1", inventTrans.inventDimId));
}
}
catch(Exception::error)
{
error("There was an error getting the record.");
}
return dimIds;
}
public List getInventSerialIds()
{
enumerator = dimIds.getEnumerator();
inventSerialIds = new List(Types::String);
while(enumerator.moveNext())
{
try
{
while select InventSerialId
from inventDim
where inventDim.inventDimId == enumerator.current()
{
inventSerialIds.addEnd(inventDim.inventSerialId);
info(strFmt("InventSerialId: %1", inventDim.inventSerialId));
}
}
catch(Exception::error)
{
error("There was an error getting the record.");
}
}
return inventSerialIds;
}
Main method to run
public static void main (Args _args)
{
YourClass yourClass = new YourClass();
YourClass.getInventSerials();
}
An output to Infolog
Comments !