Product tracker - Finding products across a branch's jobsites

How would I go about finding jobsites that uses a product for a given branch and product number?

What I have in mind: Get jobsites for a given branch → List materials for each site → Find product number in material list → Store relevant jobsite

Is there any other method for this process?

Just implemented what I mentioned and as expected, takes forever. Let me know if there’s a method I can use to make things go faster.

Hi, ejjungao.

A faster method may be to get a list (filtered by the Part Number) of Stocked Products for all Jobsites under the relevant Branch and get it’s TradingPartnerName like below -

var stockedProducts = StockedProductList.GetStockedProductList(job-site-ids, Guid.Empty, ProductType.Product);

            foreach (var item in stockedProducts.Where(p => p.PartNumber == "PARTTEST1"))
                Console.WriteLine($"ID: {item.StockingLocationID}, Jobsite: {item.TradingPartnerName}, Part No: {item.PartNumber}");

Thanks for posting.

Thanks for answering.

I think there is an issue with your logic though because this will only print 1 jobsite for 1 item, as opposed to 1 item potentially returning multiple jobsites.

Additionally, would it be possible to get the parent jobsite if the returned site is a child group? At the moment it is returning the group name, would be great if I can retrieve the main jobsite.

I’ll be adding my snippet for your review, let me know if there are some changes I can do.

TradingPartner branchOffice = TradingPartner.GetTradingPartner(branch);
StockingLocationList jobs = StockingLocationList.GetJobsites(false, JobTreeNodeDisplayType.Name,branchOffice.BusinessPartnerID, Guid.Empty);

 // List to store jobsites
List<JobSite> retrievedList = new List<JobSite>();
foreach (var job in jobs)
  {
     StockedProductList jobsite = StockedProductList.GetStockedProductList(job.StockingLocationID, Guid.Empty, ProductType.Product);
         foreach (var part in jobsite.Where(p => p.PartNumber == productID))
           {
                 // Record jobsite
           } 
   }

Hi, ejjungao.

To avoid grouping the result by part number, you may use one of the other stocked product collection objects and do the iteration. However, in the following case you may need to filter the list by PartnerType to limit it to only Jobsites and Groups. You may use TradingPartner object to do the same,

StockedProductView.GetStockedProductsByBaseProductID(Product.GetProduct("PART-NO", ProductType.Product).ProductID)

Thanks for posting.

Perfect, works very well. Thanks!

@AvontusDev
Would you happen to know why this function sometimes doesn’t return Jobsites?

I noticed for one product that it is listing only the groups under the jobsite but not the jobsite itself, as it has done for other calls to products.

Snippet:

var items = StockedProductView.GetStockedProductsByBaseProductID(Product.GetProduct(productID, ProductType.Product).ProductID);

// Getting StockingLocation details
foreach ( var item in items){
  var site = StockingLocation.GetStockingLocation(item.StockingLocationID, false);
  // Save details, etc..  
}

Hi, ejjungao.

Would you be able to post a sample database for us to be able to reproduce the behavior?

Thanks for posting.