Hi,
We have data in XLS we exported from an existing Quantify Database (Shipments). Is there a way of “importing” this data into another Quantify database using the API?
Please advise.
Hi,
We have data in XLS we exported from an existing Quantify Database (Shipments). Is there a way of “importing” this data into another Quantify database using the API?
Please advise.
Yes, you can open the file and iterate through the lines, then use the Shipment object to add the shipments. If you do a search on this site for ‘Shipment’ you’ll see several examples. Here’s one: Shipments - Add, Fetch, Filter
Do I have to worry about the inventory balances or will the API take care of that too?
No, you don’t have to worry about them. A shipment will automatically deduct from the source (branch or job) balance and add it to the destination (branch or job) balance.
More questions on this.
I can create the shipment object, but how do I add shipmentproducts? I Tried:
ship.ShipmentProducts = ShipmentProductCollection.NewShipmentProductCollection();
sp = ShipmentProduct.NewShipmentProduct();
ship.ShipmentProducts.Add(sp);
But shipmentproducts is always null. There are 2 other newshipmentproductcollections with parameters tried those too, but also null.
Please advise.
Actually, you need to load the products and then set the quantity by indexing into the ShipmentProducts collection. If it’s null then it hasn’t been loaded. Here’s some better sample code.
// Set the branch ID to the branch that you're shipping from
Guid branchID = Guid.Empty;
// Set the job ID to the job that you're shipping to
Guid jobID = Guid.Empty;
// New shipment
Shipment ship = Shipment.NewShipment(ShipmentStatusType.NewDirectShip);
// Set the from and to locations
ship.FromStockingLocationID = branchID;
ship.ToStockingLocationID = jobID;
ship.IsBillable = false;
// This loads the shipoment products
ship.ShipmentProducts.AddCatalogParts(branchID, jobID, Guid.Empty);
// Grab your data here
string partNumber = "";
double qty = 0;
// If shipment contains product then add to it. If it
// doesn't contain the product then the part number doesn't exist
if (ship.ShipmentProducts.Contains(partNumber, Guid.Empty))
{
// Add quantity to itself if it exists
if (ship.ShipmentProducts[partNumber, Guid.Empty].SentQuantity != null &&
ship.ShipmentProducts[partNumber, Guid.Empty].SentQuantity > 0)
{
qty = (ship.ShipmentProducts[partNumber, Guid.Empty].SentQuantity ?? 0) + qty;
}
ship.ShipmentProducts[partNumber, Guid.Empty].SentQuantity = qty;
}
// If it's savable then save
if (ship.IsSavable)
{
try
{
ship.Save();
}
catch (DataPortalException ex2)
{
ship = (Shipment)ex2.BusinessObject;
if (ship.BrokenRulesCollection.Count > 0)
Console.WriteLine("ERROR: Shipment not savable BrokenRules: " + ship.BrokenRulesCollection.ToString());
foreach (ShipmentProduct prod in ship.ShipmentProducts)
if (prod.BrokenRulesCollection.Count > 0)
Console.WriteLine("Part,Qty: " + prod.PartNumber + "," + prod.SentQuantity.ToString() + " on shipment not savabable BrokenRules: " + ship.BrokenRulesCollection.ToString());
}
}
else
{
// Else there's some other issue that
// needs to be taken care of, check
// broken rules on the shipment and products
if (ship.BrokenRulesCollection.Count > 0)
Console.WriteLine("ERROR: Shipment not savable BrokenRules: " + ship.BrokenRulesCollection.ToString());
foreach (ShipmentProduct prod in ship.ShipmentProducts)
if (prod.BrokenRulesCollection.Count > 0)
Console.WriteLine("Part,Qty: " + prod.PartNumber + "," + prod.SentQuantity.ToString() + " on shipment not savable BrokenRules: " + ship.BrokenRulesCollection.ToString());
}
“If it’s null then it hasn’t been loaded” <-- What does this mean?
Do I have to put a time and wait or wait for an event to notify that the products are loaded? Or is there a function I am missing that will load them?
ship.ShipmentProducts.AddCatalogParts(branchID, jobID, Guid.Empty); does not work because shipmentproducts is still null to begin with, so I don’t understand what I am missing here.
I modified the code to use ship = Shipment.NewShipment(ShipmentStatusType.NewDirectShip), and ShipmentProducts is not null anymore, but now I have another issue.
ship.ShipmentProducts.AddCatalogParts(new Guid(“9707857F-A39A-4A10-8D9C-B686132C73BC”), new Guid(“DC10CB5C-267A-40BC-AFB9-08C2687532A6”), Guid.Empty);
Either takes forever (several minutes) or throws a locking issue. I am on a different machine than the server, so will changing the app to the server directly will improve performance?
At this point it is unusable since it may or may not load the products using that same line of code.
Please advise.
Hi Mario. Will send some revised code. Can you clarify what the locking issue is? Is it an exception?
Here’s some revised code for when creating the shipment. Looks like I forgot to set the types. When setting the product quantities the code is the same.
Shipment ship = Shipment.NewShipment(ShipmentStatusType.NewDirectShip);
ship.FromStockingLocationID = branch.StockingLocationID;
ship.FromLocationType = SourceType.BranchOffice;
ship.ToStockingLocationID = job.StockingLocationID;
ship.ToLocationType = SourceType.JobSite;
ship.ShipmentProducts.AddCatalogParts(branch.StockingLocationID, job.StockingLocationID, Guid.Empty);
ship.ShipmentNumber = shipmentNumber;
ship.ActualShipDate = DateTime.Today.ToShortDateString();
ship.PlannedShipDate = ship.ActualShipDate;
ship.ReceiveDate = ship.ActualShipDate;
ship.RentStartDate = firstDay.ToShortDateString();
// Grab your data here
string partNumber = "";
double qty = 0;
// If shipment contains product then add to it. If it
// doesn't contain the product then the part number doesn't exist
if (ship.ShipmentProducts.Contains(partNumber, Guid.Empty))
{
// Add quantity to itself if it exists
if (ship.ShipmentProducts[partNumber, Guid.Empty].SentQuantity != null &&
ship.ShipmentProducts[partNumber, Guid.Empty].SentQuantity > 0)
{
qty = (ship.ShipmentProducts[partNumber, Guid.Empty].SentQuantity ?? 0) + qty;
}
ship.ShipmentProducts[partNumber, Guid.Empty].SentQuantity = qty;
}
// If it's savable then save
if (ship.IsSavable)
{
try
{
ship.Save();
}
catch (DataPortalException ex2)
{
ship = (Shipment)ex2.BusinessObject;
if (ship.BrokenRulesCollection.Count > 0)
Console.WriteLine("ERROR: Shipment not savable BrokenRules: " + ship.BrokenRulesCollection.ToString());
foreach (ShipmentProduct prod in ship.ShipmentProducts)
if (prod.BrokenRulesCollection.Count > 0)
Console.WriteLine("Part,Qty: " + prod.PartNumber + "," + prod.SentQuantity.ToString() + " on shipment not savabable BrokenRules: " + ship.BrokenRulesCollection.ToString());
}
}
else
{
// Else there's some other issue that
// needs to be taken care of, check
// broken rules on the shipment and products
if (ship.BrokenRulesCollection.Count > 0)
Console.WriteLine("ERROR: Shipment not savable BrokenRules: " + ship.BrokenRulesCollection.ToString());
Hi, I was able to get the import to work with the above code, thanks!.
But there were some records that were not savable (ship.IsSavable == false). I did a force validation but there are no broken rules.
Is there a way to determine why these records are not savable? At first glance I cannot see what is wrong with them.
Nevermind, I looked at the ShipmentProducts broken rules.
Great! Glad that you got it working OK.