Page 1 of 1

How do I check if a Work Order has unallocated components

PostPosted: Thu Jul 23, 2026 9:26 pm
by indikad
What is the best way to determine whether a Work Order still has unallocated component allocations?


I am trying to do this check on the save_start of Work Order window.

Is there already a WorkOrder property/method that indicates allocations are incomplete?
Should I be checking Stages, InputItems, OutputItems, LineDetails, or some other collection?
Which property indicates that an allocation is still outstanding/unallocated?

A small code example would be greatly appreciated.
Thanks.

the code below is the skeleton i have so far

Code: Select all
 public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
    {      
      if(JiwaForm is JiwaFinancials.Jiwa.JiwaBillOfMaterialsUI.WorkOrder.WorkOrder )
        {
            JiwaFinancials.Jiwa.JiwaBillOfMaterialsUI.WorkOrder.WorkOrder  workOrderForm = (JiwaFinancials.Jiwa.JiwaBillOfMaterialsUI.WorkOrder.WorkOrder )JiwaForm;
            workOrderForm.WorkOrder.SaveStart += WorkOrder_SaveStart;
        }
    }
   private void WorkOrder_SaveStart(object sender, EventArgs e)
   {
      // works but count = 0
       JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.WorkOrder workOrder =(JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.WorkOrder)sender;

       foreach (JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.OutputItem outputItem in workOrder.OutputItems)
       {
           MessageBox.Show(
               "Output Item: " + outputItem.ItemNo + Environment.NewLine +
               "LineDetails Count: " +
               outputItem.LineDetails.Count.ToString());  // no errors but gives a count = 0 which is not right ??
            
           //break;
       }      
      
   }

Re: How do I check if a Work Order has unallocated component

PostPosted: Fri Jul 24, 2026 2:33 pm
by Mike.Sheen
Code: Select all
outputItem.LineDetails.Count.ToString());  // no errors but gives a count = 0 which is not right ??


I'm not sure why you assert that the count of LineDetails for an output item should not be 0 - that just means at that point no output stock has been defined - it's normal if the output quantity is 0 for there to be no line details.

The work order has a property, Allocations - which is a collection of allocations between inputs and outputs - it has a property TotalQuantityOutputUnAllocated which I think is what you are after.

So you can do something like:,

Code: Select all
if (workOrder.Allocations.TotalQuantityOutputUnAllocated > 0)
{
    // there are unallocated amounts.
}

Re: How do I check if a Work Order has unallocated component

PostPosted: Fri Jul 24, 2026 4:09 pm
by indikad
Hi Mike,

Thanks for replying early.
<< I'm not sure why you assert that the count of LineDetails for an output item should not be 0>>
TBH I am not sure why too. I have been throwing all different kinds of logic and code at this and this is the last of the pile i had.


the code gave me an error on Jiwa 7.2.1 as below
on the code line
if (workOrder.Allocations.TotalQuantityOutputUnAllocated > 0)

Err:
JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.LineDetailsAllocationCollection.TotalQuantityOutputUnAllocated' is not supported by the language; try directly calling accessor method 'JiwaFinancials.Jiwa.JiwaBillOfMaterials.Work

Re: How do I check if a Work Order has unallocated component

PostPosted: Fri Jul 24, 2026 4:16 pm
by Mike.Sheen
indikad wrote:the code gave me an error on Jiwa 7.2.1 as below
on the code line
if (workOrder.Allocations.TotalQuantityOutputUnAllocated > 0)

Err:
JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.LineDetailsAllocationCollection.TotalQuantityOutputUnAllocated' is not supported by the language; try directly calling accessor method 'JiwaFinancials.Jiwa.JiwaBillOfMaterials.Work


Oh, ok - I should have tested that - I didn't look closely enough - that property actually wants a parameter - a line detail of an output item.

So you would need to loop through output item, and for each one of those loop through the linedetail and pass that linedetail as a parameter to TotalQuantityOutputUnAllocated - it will return how much of that linedetail is unallocated.

There are other properties next to that one which might be more useful - like TotalQuantityInputAllocated - it all depends on what you're trying to do, and at what point your plugin is wanting to do it.

Re: How do I check if a Work Order has unallocated component

PostPosted: Fri Jul 24, 2026 5:29 pm
by indikad
Hi Mike,

My goal is to prevent closure of a Work Order when components remain unallocated - so I am looking for a property I should test ( if available ) .
Is there a property/method on Allocations that directly tells me:

input quantity required
input quantity allocated
input quantity unallocated

and can you provide a code sample on a Work Order SaveStart validation please ?

Re: How do I check if a Work Order has unallocated component

PostPosted: Fri Jul 24, 2026 5:52 pm
by Mike.Sheen
Code: Select all
private void WorkOrder_SaveStart(object sender, System.EventArgs e)
{
   JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.WorkOrder workOrder = (JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.WorkOrder)sender;
   
   foreach(JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.OutputItem outputItem in workOrder.OutputItems)
   {
      foreach(JiwaFinancials.Jiwa.JiwaApplication.Inventory.SOH.LineDetail<JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.OutputItem> outputLineDetail in outputItem.LineDetails)
      {
         if (workOrder.Allocations.get_TotalQuantityOutputUnAllocated(outputLineDetail) > 0)
         {
            throw new Exception(String.Format("Output item {0} has a line detail not fully allocated.", outputItem.Inventory.PartNo));
         }
                     
         // workOrder.Allocations.get_TotalQuantityOutputAllocated(outputLineDetail) returns the total allocated (as opposed to unallocated)
         // And there are also other methods for input items:
         // workOrder.Allocations.get_TotalQuantityInputAllocated(inputItem)
         // workOrder.Allocations.get_TotalQuantityInputAllocated(inputLineDetail)
         // workOrder.Allocations.get_TotalQuantityInputAllocated(inputItem, outputLineDetail)
         // workOrder.Allocations.get_TotalQuantityInputAllocated(inputLineDetail, outputItem)
         // workOrder.Allocations.get_TotalQuantityInputAllocated(inputLineDetail, outputLineDetail)
      }
   }
}


Working plugin attached.

Re: How do I check if a Work Order has unallocated component

PostPosted: Tue Jul 28, 2026 5:46 pm
by indikad
Hi Mike,

thanks for this - i will hold on to this sample. That compiles well.
However , what I'm after is input components , not output - ie; when someone saves the order I want to capture if any of the input component has been partially allocated. Example of a demo data wok order is pasted.
In this case the item “test” is partially allocated.
Based on your code – (which is looking at the output components) I tried to create a scenario for input components but I am getting a compilation error.
Besides that I want to use it on the Form Plugin as opposed to business logic plugin which you have used.
What should I do to make it work pls - what am I missing?
My code sample attached.,


Error:
Message
'JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.WorkOrder' does not contain a definition for 'InputItems' and no extension method 'InputItems' accepting a first argument of type 'JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.WorkOrder' could be found (


Code: Select all
public class FormPlugin : System.MarshalByRefObject, JiwaFinancials.Jiwa.JiwaApplication.IJiwaFormPlugin
{

    public override object InitializeLifetimeService()
    {
        // returning null here will prevent the lease manager
        // from deleting the Object.
        return null;
    }

    public void SetupBeforeHandlers(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
    {
    }

    public void Setup(JiwaFinancials.Jiwa.JiwaApplication.IJiwaForm JiwaForm, JiwaFinancials.Jiwa.JiwaApplication.Plugin.Plugin Plugin)
    {      
      if(JiwaForm is JiwaFinancials.Jiwa.JiwaBillOfMaterialsUI.WorkOrder.WorkOrder )
        {
            JiwaFinancials.Jiwa.JiwaBillOfMaterialsUI.WorkOrder.WorkOrder  workOrderForm = (JiwaFinancials.Jiwa.JiwaBillOfMaterialsUI.WorkOrder.WorkOrder )JiwaForm;
            workOrderForm.WorkOrder.SaveStart += WorkOrder_SaveStart;
        }
    }
   
   private void WorkOrder_SaveStart(object sender, System.EventArgs e)
   {
      JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.WorkOrder workOrder = (JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.WorkOrder)sender;
      
      foreach(JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.InputItem inputItem in workOrder.InputItems) // error
      {
         foreach(JiwaFinancials.Jiwa.JiwaApplication.Inventory.SOH.LineDetail<JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.InputItem> inputLineDetail in inputItem.LineDetails)
         {
            if (workOrder.Allocations.get_TotalQuantityOutputUnAllocated(inputLineDetail) > 0)
            {
            MessageBox.Show("SaveStart fired for Work Order " + workOrder.ToString(), "Test");
               throw new Exception(String.Format("Input item {0} has a line detail not fully allocated.", inputItem.Inventory.PartNo));
            }                     
            
         }
      }
   }
   
   private void MikesVersion_WorkOrder_SaveStart(object sender, System.EventArgs e)
   {
      JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.WorkOrder workOrder = (JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.WorkOrder)sender;
      
      foreach(JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.OutputItem outputItem in workOrder.OutputItems)
      {
         foreach(JiwaFinancials.Jiwa.JiwaApplication.Inventory.SOH.LineDetail<JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.OutputItem> outputLineDetail in outputItem.LineDetails)
         {
            if (workOrder.Allocations.get_TotalQuantityOutputUnAllocated(outputLineDetail) > 0)
            {
               throw new Exception(String.Format("Output item {0} has a line detail not fully allocated.", outputItem.Inventory.PartNo));
            }
                        
            // workOrder.Allocations.get_TotalQuantityOutputAllocated(outputLineDetail) returns the total allocated (as opposed to unallocated)
            // And there are also other methods for input items:
            // workOrder.Allocations.get_TotalQuantityInputAllocated(inputItem)
            // workOrder.Allocations.get_TotalQuantityInputAllocated(inputLineDetail)
            // workOrder.Allocations.get_TotalQuantityInputAllocated(inputItem, outputLineDetail)
            // workOrder.Allocations.get_TotalQuantityInputAllocated(inputLineDetail, outputItem)
            // workOrder.Allocations.get_TotalQuantityInputAllocated(inputLineDetail, outputLineDetail)
         }
      }
   }
   
   
   
   

}
#endregion


Re: How do I check if a Work Order has unallocated component

PostPosted: Tue Jul 28, 2026 5:50 pm
by Mike.Sheen
Code: Select all
foreach(JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.InputItem inputItem in workOrder.InputItems) // error


The error is exactly as stated by the compiler - WorkOrder does not have a property named InputItems.

InputItems is a property of a Stage.

WorkOrder has a collection of Stage, named Stages - and each Stage has InputItems.

Code: Select all
foreach(JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.Stage stage in workOrder.Stages)
{
   foreach(JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.InputItem inputItem in stage.InputItems)
   {
      if (inputItem.QuantityAllocated < inputItem.Quantity)
      {
         // not fully allocated
      }            
   }
}


Or

Code: Select all
// Alternatively, per input item line detail:
foreach(JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.Stage stage in workOrder.Stages)
{
   foreach(JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.InputItem inputItem in stage.InputItems)
   {
      foreach(JiwaFinancials.Jiwa.JiwaApplication.Inventory.SOH.LineDetail<JiwaFinancials.Jiwa.JiwaBillOfMaterials.WorkOrder.InputItem> inputLineDetail in inputItem.LineDetails)
      {
         if (workOrder.Allocations.get_TotalQuantityInputAllocated(inputLineDetail) != inputLineDetail.Quantity)
         {
            // this line detail is not fully allocated
         }
      }
   }
}