uBAQ update UD field on approved POs

I created an updateable dashboard from a uBAQ that update a UD field (comments) on existing POs. The dashboard works as intended but after typing a comment, the user has to click save and then hit refresh to get the PO unnaproved, the comments updated and the PO reapproved . If the user doesnt hit refresh then POs remain unapproved. This lead to some frustation on the user part. To improve the user’s experience, I tried automating the refresh function using this thread: Dashboard Customization And dashboard refresh

I created a customization for this dashboard, in which I used Jose’s code and it works great in Pilot. Whenever I enter a comment and click “save”, the PO gets unapproved, the comment gets added to the UD field, the refresh function gets automatically called and the PO gets reapproved.

However, whenever I apply the same customization in the Live environment, It doesn’t work as intended. Whenever I enter a comment then click save, it goes straight to Refreshing the dashboard without unapproving the PO and adding my comments first…

What am I missing ?

Rather than a customization you can do the unapproval and reapprove behind the scenes so the user is not aware they happened. If I am doing my own update these there are in the same code block. If I am using Epicor’s update then you can do them preprocessing and post on update or just make sure the order field runs them before and after the update.

This is also a future proof way to approach.

unapprove

foreach (var ttResultsRow in queryResultDataset.Results.Where(ttResults_Row => !ttResults_Row.Unchanged()))
{
    
    POHeader = Db.POHeader.Where(POHeader_Row=> POHeader_Row.Company == Session.CompanyID && POHeader_Row.SysRowID == ttResultsRow.POHeader_SysRowID).FirstOrDefault();
    if (POHeader != null)
    {
        POHeader.Approve = false;
        POHeader.ApprovalStatus = "U";
    }
}

reapprove


 foreach (var ttResultsRow in queryResultDataset.Results.Where(ttResults_Row => !ttResults_Row.Unchanged()))
{   
    POHeader = Db.POHeader.Where(POHeader_Row=> POHeader_Row.Company == Session.CompanyID && POHeader_Row.SysRowID == ttResultsRow.POHeader_SysRowID).FirstOrDefault();
    if (POHeader != null)
    {
        POHeader.Approve = true;
        POHeader.ApprovalStatus = "A";
    }
}
4 Likes

Thanks a lot Greg, this worked perfectly!

1 Like

Thanks for this post. It’s so nice to discover that others have already struggled with what I am struggling with!

Another solution … Instead of Pre and Post directives that check if the PO is approved and then unapprove and reapprove, add one Base processing directive to do the update. The unapprove/reapprove is not necessary when you use the Db context instead of the business object because it bypasses business logic. Do this only for UD fields where you know there is no business logic needed.

Thanks to @mbayley for this solution.

In the uBAQ: In Update Processing > Advanced BPM configuration, add a Base processing directive on the Update method. Add a custom code widget with the following:

foreach (var row in queryResultDataset.Results.Where(o=> o.Updated()))
{
var po = Db.POHeader.First(o=> o.Company == CompanyID && o.PONum == row.POHeader_PONum);

// Update POWatch_c
po.POWatch_c = row.POHeader_POWatch_c;
}

Db.SaveChanges();