Search code examples
acumatica

Enter Physical Inventory Count Through Acumatica API


Can someone please provide me with an example on how to enter a PI Count through the API. I used the following code which worked fine at the beginning, but I cannot enter a count for an Item/Location combination which does not figure in the initial PI Count list released directly from Acumatica.

IN305010Content IN305010 = oScreen.IN305010GetSchema();
oScreen.IN305010Clear();

List<Command> oCmds = new List<Command>();

oCmds.Clear();

oCmds.Add(new Key { Value = StocktakeRef, FieldName = IN305010.DocumentSummary.ReferenceNbr.FieldName, ObjectName = IN305010.DocumentSummary.ReferenceNbr.ObjectName, Commit = true });
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
  oCmds.Add(new Key { Value = "='" + ds.Tables[0].Rows[i].ItemArray[2].ToString() + "'", FieldName = IN305010.PhysicalInventoryDetails.InventoryID.FieldName, ObjectName = IN305010.PhysicalInventoryDetails.InventoryID.ObjectName });
  oCmds.Add(new Value { Value = "='" + ds.Tables[0].Rows[i].ItemArray[5].ToString() + "'", FieldName = IN305010.PhysicalInventoryDetails.Location.FieldName, ObjectName = IN305010.PhysicalInventoryDetails.Location.ObjectName, Commit = true });
  oCmds.Add(new Value { Value = ds.Tables[0].Rows[i].ItemArray[3].ToString(), LinkedCommand = IN305010.PhysicalInventoryDetails.PhysicalQuantity, Commit = true});
}

oCmds.Add(IN305010.Actions.Save);
oScreen.IN305010Submit(oCmds.ToArray());

Thanks, G


Solution

  • This is the code that fixed my issue if anyone needs it

    IN305010Content IN305010 = oScreen.IN305010GetSchema();
    oScreen.IN305010Clear();
    
    List<Command> oCmds = new List<Command>();
    
    oCmds.Clear();
    
    oCmds.Add(new Key { Value = StocktakeRef, FieldName = IN305010.DocumentSummary.ReferenceNbr.FieldName, ObjectName = IN305010.DocumentSummary.ReferenceNbr.ObjectName, Commit = true });
    oCmds.Add(new Value { Value = "OK", LinkedCommand = IN305010.AddLine.ServiceCommands.DialogAnswer, Commit = true });
    oCmds.Add(new Value { Value = "True" , FieldName = IN305010.AddLine.AutoAddLine.FieldName, ObjectName = IN305010.AddLine.AutoAddLine.ObjectName, Commit = true });
    
    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
    {
      oCmds.Add(new Value { Value = "OK", LinkedCommand = IN305010.AddLine.ServiceCommands.DialogAnswer, Commit = true });
      oCmds.Add(new Value { Value = <<"Qty">>, FieldName = IN305010.AddLine.Qty.FieldName, ObjectName = IN305010.AddLine.Qty.ObjectName });
      oCmds.Add(new Value { Value = <<"Item">>, FieldName = IN305010.AddLine.InventoryID.FieldName, ObjectName = IN305010.AddLine.InventoryID.ObjectName, Commit = true });
      oCmds.Add(new Value { Value = <<"Location">>, FieldName = IN305010.AddLine.LocationID.FieldName, ObjectName = IN305010.AddLine.LocationID.ObjectName, Commit = true });
      oCmds.Add(new Value { Value = "True", LinkedCommand = IN305010.Actions.AddLine2, Commit = true });
    }
    oCmds.Add(IN305010.Actions.Save);
    oScreen.IN305010Submit(oCmds.ToArray());
    

    Cheers, G