UBAQ to update Primary Warehouse and Bin

What you’re describing sounds like the issue I originally ran into. Make sure that the code you have is looping through the part dataset to find the correct record to update. My original code was just always updating the first one.

Yeah… if you hadn’t figured it out (though I’m sure you could), there is no way that I will.

Hi @JasonMcD
What does your code look like? And when do you get the Modified by Another User Error?

Jose,

I didn’t modify much, except to replace MfgSys with r.PlantWhse_Plant

And I added the assembly of Erp.BO.Contracts.PartOnHandWhse.

The error is on update (BAQ) or save (dashboard).

int i = 0;

foreach(var r in ttResults.Where(r=>r.Updated()))
{
    using(var partWhseBO = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.PartOnHandWhseSvcContract>(Db))
  {
      partWhseBO.GetPartOnHandWhse(r.PlantWhse_PartNum, r.PlantWhse_Plant);
    }

  using(var partBO = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.PartSvcContract>(Db))
  {
        string binDesc = (
          from wb in Db.WhseBin.With(LockHint.NoLock)
          where wb.Company==Session.CompanyID && wb.BinNum==r.PlantWhse_PrimBin
          select wb.Description).ToString();  

            PartTableset pds = new PartTableset();
        pds = partBO.GetByID(r.PlantWhse_PartNum);

        pds.PartWhse[i].WarehouseCode = r.PlantWhse_WarehouseCode;
            pds.PartWhse[i].PrimBinNum = r.PlantWhse_PrimBin;
            pds.PartWhse[i].PrimBinNumDescription = binDesc;
        pds.PartWhse[i].RowMod = "U";
            partBO.Update(ref pds);

        i++;
  }
}

By the way, for me at least, I wasn’t trying to do a batch save. Just one row at a time.

So your i counter is only increasing once for each ttResult however if you have multiple warehouses that means you are only updating the first one first (0) then the second one (1) and so on…

Are you trying to update the PrimaryBin on all found warehouses?

No, just one.

Can you give me a screenshot of what your input screen / data looks like?

image

Just trying to update only the last one, for example.

right ok so you need to find the “Right” Warhouse Record to update try this… (note I don’t have a syntax checker)

foreach(var r in ttResults.Where(r=>r.Updated()))
{
  using(var partBO = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.PartSvcContract>(Db))
  {
        string binDesc = (
          from wb in Db.WhseBin.With(LockHint.NoLock)
          where wb.Company==Session.CompanyID && wb.BinNum==r.PlantWhse_PrimBin
          select wb.Description).ToString();  

            PartTableset pds = new PartTableset();
        pds = partBO.GetByID(r.PlantWhse_PartNum);

		var partWhseRecord = pds.PartWhse.Where(rr=>rr.WarehouseCode == r.PlantWhse_WarehouseCode).FirstOrDefault();
		if(partWhseRecord!=null)
		{
			partWhseRecord.WarehouseCode = r.PlantWhse_WarehouseCode;
            partWhseRecord.PrimBinNum = r.PlantWhse_PrimBin;
            partWhseRecord.PrimBinNumDescription = binDesc;
			partWhseRecord.RowMod = "U";
            partBO.Update(ref pds);
        }
  }
}
2 Likes

If that doesn’t work let me know we may need to use a BeforeImage.;

Awesome, I think that works!

For future readers, only minor syntax issue was the ~= null instead of !=null.

@josecgomez No syntax errors at all!

What syntax error

Well, this had some unintended consequences.

The pic below is a BAQ on PlantWhse. There is honestly no PDC warehouse in the MfgSys site. It does not exist and is not shared. But records got created in PlantWhse for this imaginary warehouse.

This has two consequences.

  1. Time Phase shows 129 for this part number in MfgSys alone, and that’s not true, and the running balance is calculated off of that number. Some parts of Part Tracker also show 129 (bin and site OH numbers).
  2. A report I made to replace the Sales Order Pick List shows no primary bin for this part.

I can probably fix the BAQ for the report, and I already direct people away from Time Phase and to a custom version of it I created anyway (and it has accurate numbers).

Not sure how to avoid this. Is there a way to specify the plant in this partWhseRecord?

I do believe I have licked this. No BPM and no code whatsoever. (No promises on multiple rows, though, @hmwillett.)

The business object to use is Part, and you are (pseudo) updating the PartWhse table. (NOT PlantWhse as it does not exist in the tree here.)

When I did that, I also had to add in the “Query to Object” mapping rows by hand, one by one.

I don’t have anything in the other mapping tab, except what it did automatically (part description). I’m not adding new rows here. And I had tinkered with it, but ended up making a mess, so I left it alone.

Can anyone just give us an export of a working UBAQ for this? I need one as well

1 Like

@nyamoga9 Here you go. It’s been working well here. (No complaints, anyway.)

UPDATE_PrimaryBin_v2a.baq (41.4 KB)

Technical note: I deliberately tied it to PartPlant, since that inherently restricts the user to be able to only edit bins in a site he or she has access to. If you delete that table from the BAQ, the user can edit the primary bin in all warehouses in all sites.

5 Likes

Thanks :slight_smile:

Great work and thank you for your solution.

1 Like

Thank you Jason. I know this was created years ago, but it saved me a lot of time today!

1 Like