uBAQ not updating PO.DocUnitCost

I have created a uBAQ to update the promise dates and due dates of the PO Header as well as PO Rel level dates. Using a updatable BAQ directive, I am unapproving, updating the data, and reapproving the PO. (Thanks to @danbedwards) . I have attempted to add a field to update PODetail.DocUnitCost as well, but it isnt working. When I change it in the BAQ test or on the Dashboard it just goes back to its original value. It does not show any error and says the update was fulfilled. (Field help says Unit Price is PODetail.DocScrUnitCost but this doesn’t show up in PODetail) Why will it not update? If I go into PO Entry, I can unapprove the PO and make the change just like changing the dates so I wouldn’t think it would be any different.

I would also like to be able to push the changed header level promise date and due dates to all of the releases much like it does PO Entry after a prompt asking if it should be pushed through. Does anyone have any ideas on how to accomplish this as well.

Here is the BAQ for reference: 2044.baq (128.0 KB)
Apologies if the BPM directive is not attached.

Thanks in advance.

1 Like

Here is a way you can update the Unit Price.


This is the ##BASE## directive after you save the UBAQ with the fields you wish to update.
1 - Set ttResults.POHeader_Approve = false
2 - Set ttResults.POHeader_ReadyToPrint = false
3 - Set ttResults.POHeader.ApprovalStatus = “U”
Changed Row for 1 - 3
4 - Fill Table By Query (create TableSet variable based on POTableSet)
4a - Source will be ttResults
4b - Mapping will be all custom fields that the standard UBAQ logic (#5) does not handle
4c - This table will be used quite a bit
5 - Standard UBAQ code (no changes)
6 - Call PO.GetByID to new variable ds (PO) using ttResultsRow. (PONUM)
7 - Set PO.POHeader.Approve = false (changed row)
8 - Custom Code

// SaveResults = POTableSet from #4
// PO = ds from #6
// Just sample for UnitCost
var ResultRows = SavedResults.PODetail.Where(sr => sr.RowMod == "U");
foreach(var ResultRow in ResultRows)
  {
      int PONum = ResultRow.PONUM;
      int POLine = ResultRow.POLine;
      decimal Cost = ResultRow.DocUnitCost;
      var PORows = PO.PODetail.Where(po => po.Company == Session.CompanyID && po.PONUM == PONum && po.POLine == POLine);
      foreach(var PORow in PORows)
        {
            PORow.RowMod = "U";
            PORow.ScrUnitCost = Cost;
        }
  }

9 - PO.ChangeUnitPrice using var:PO
10 - PO.Update BO referencing var:PO
11 - Set ApprovalStatus to “A”
12 - Set ReadyToPrint = true
13 - Set Approve = true
For 11 - 13 All rows
14 - Custom Code to Set RowMod = U in PO.POHeader
15 - Run PO.Update using PO ds
16 - Not really need but custom code that takes the PO variable and then update ttResults to get the screen to show all the update values. Can be done client side in Dashboard code as well on refresh.

var ResultRows = SavedResults.PODetail.Where(sr => sr.RowMod == "U");
foreach(var ResultRow in ResultRows)
  {
    int PONum = ResultRow.PONUM;
    int POLine = ResultRow.POLine;
    decimal Cost = ResultRow.DocUnitCost;
    var Result = ttResults.Where(t => t.PODetail_PONUM == PONum && t.PODetail_POLine == POLine);
    foreach (var Row in Result)
      {
          Row.PODetail_DocUnitCost = Cost;
      }
  }
1 Like

I am pretty sure there is an example of this one if you search. If you have already search with no luck I can post something.

Thanks for this wonderful post. I just have a some clarification questions to hopefully get this working.

Could you explain what display fields to add? It appears that DocUnitCost is handled in the standard UBAQ logic. I currently have PONum, POLine, and DocUnitCost.

Is this setting the fields on the PO tableset variable or is this actually changing ttResultRows? Currently assuming the variable PO.

Will this alone handle my other updatable fields such as approve, confirmed, promise date and due date?

I am currently getting “BPM runtime caught an unexpected exception of ‘NullReferenceException’ type.
See more info in the Inner Exception section of Exception Details.”
The Unit Price is still not changing and the PO is not being reapproved after I click GetList again.

I am not sure what is happening. I have inserted three different Show Message widgets to see where the error is occurring (before Fill Table by Query, before Defaultmpl, and before ChangeUnitPrice). None of them ever pop up. The only thing I am doing before the first show message is changing the 3 fields in ttResultsRow which should clearly work as it did before.

example.pdf (227.9 KB) POUpdate.baq (88.0 KB) Try loading this example. Import the BAQ and then review the PDF for additional steps. This is just a quick example that should answer your questions.

1 Like

Thanks again for your help. Your detailed instructions and help is very much appreciated!

Hi Dan. Thanks again for your help. I cant seem to find what I am looking for on this forum. Could you post something about how to accomplish this?

Are you looking for instructions for searching in general?

Did you look at this? Searching Help

I could not find anything for how to push the changed header dates to all of the Lines/Rel like PO Entry does when saving after changing the header dates. (It prompts the user if they would like to update all of the releases with the new date)

I am also doing something similar, but I only need to update the UnitCost field. For the most part the solution posted works, and I can change the UnitCost easily. The only problem is that if the PO has multiple releases, it causes a Null Reference Exception. It still updates the UnitCost and saves it to the database, but I don’t want this exception showing up. I do not know why having multiple releases causes this, any help would be appreciated

I am not sure that I ever found a solution for this. I am assuming if you can trace exactly where the exception is triggered, you could find a way to catch it or ignore it somehow with custom code. Not sure what that would look like though.