Create new line and release from UBAQ custom code

Hi again!

I have an UBAQ that lists some sales order (release) data (from UD02) for the user. There is a checkbox (using a custom action) that allows the user to create a new release with the information in the record.

This works well when the line exists within the order. But when I need to make a new line, I can’t figure out how to update the new release that gets automatically created. I can create the line, and create a new release on that line (which becomes the second release) and I can update that second release. But it leaves the first empty release in there on the line. I started another thread to try to delete a release, with this end in mind. How to Delete a Release Using a Custom Action.

I’d like to complete this all in one custom action. As a result things look a bit messy. I have tried looping from the newly created line back to the release update path, but it didn’t update the first release. I tried recreating the release update path separately just for new line releases. No luck. I did try to update the new line release though custom code, but I am afraid I am not that familiar with the syntax.

I will try to post the image and the code I have so far. Please let me know if there is anything else you need, or that I didn’t explain.

Thanks for your time!

Custom Code Elements:

Pull In Data: (This pulls data from ttResults, including new release data from UD02. We just populate some internal variables to use in methods later.)

var ttResults_xRow = (from ttResults_Row in ttResults where ttResults_Row.Calculated_NewRelease == true select ttResults_Row).FirstOrDefault();

if (ttResults_xRow != null)
  totalrows = ttResults.Count / 2; //not sure why this is divided by 2, but it works...
  if (myrow <= totalrows)
        MyOrder = ttResults_xRow.OrderHed2_OrderNum;

        if (String.IsNullOrEmpty(Convert.ToString(ttResults_xRow.OrderDtl1_OrderLine)))
          MyLine = 0;
          MyLine = ttResults_xRow.OrderDtl1_OrderLine;
        MyQty = ttResults_xRow.UD02_Number01;
        MyDate = ttResults_xRow.UD02_Date01;
        MyPart = ttResults_xRow.UD02_ShortChar01;
        MyFalse = false;
        MyuomCode = "";
        MyID = ttResults_xRow.SysRowID;
        ttResults_xRow.Calculated_NewRelease = false;

Set My Line: (This is just to figure out what the newly create line number is.)

var OrderDtl = (from row in Db.OrderDtl where row.Company == Session.CompanyID && row.OrderNum == MyOrder orderby row.OrderLine descending select row).FirstOrDefault();
      MyLine = OrderDtl.OrderLine;

Delete First Rel: (This just closes the first release on a newly created line. It should delete it instead.)

if (IsNewLine == true)

using (Erp.Contracts.SalesOrderSvcContract soSvc =  Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.SalesOrderSvcContract>(Db))
         soSvc.CloseRelease(MyOrder, MyLine, 1);
         soSvc.Update(ref MyVar);       

This is related to another topic I created:

To help wrap up this post, can anyone clarify exactly how to use the GetNewOrderRel method from the Sales Order BO? I want to populate the record that is created, but the segment below doesn’t populate the right record. Instead it populates a new second release, leaving the first release blank. The SetField widgets all update the added row. I used the same dataset variable throughout each widget. The first widget is GetNewOrderRel, the second is ChangeSellingReqQty.

Although I am not currently using it, I have a feeling RowMod may come into play here someplace. What am I missing?


I also tried to use an update table by query widget to change the values of the newly added row, right after GetNewOrderRel. No matter what I do, I cannot seem to update that first default release.

I think I have been approaching this wrong. Since the new release is created at the time the new line is created, I think that right after I create the new line, I may need to use an update table by query widget to insert the release quantities dates, and flags. I am trying various combinations now. I sure would appreciate a nudge in the right direction.

I figured it out! I had to update the dataset after GetNewOrderDtl. Then I could just find the new line and update the first record in it. Seems obvious now, but it took me a while to get here!
It goes something like this:

  1. GetNewOrderDtl - to create a new line.
  2. Update required fields in OrderDtl.
  3. Update the dataset used to create the line.
  4. Update the OrderRel table in the dataset by filtering by the new line number, and the first release, don’t forget to set rowmod=“U”.
  5. Update the dataset again.

Just let me know if you have any questions or suggestions!

1 Like

Hey Nate, just looking through this as I have a somewhat similar requirement. Is this uBAQ being called through rest services?

I don’t think so. I am not sure exactly what REST is, but I am pretty sure I don’t use it.

So as I understand you’re building a custom action on this ubaq and then invoking a series of BO calls in the custom action? When your user selects that custom action, it executes the series of transactions
I’m considering something like this in place of the current calls being made from a web app since this would allow the web app logic to be simple and the complex part would be on the epicor side

This is how I do all my integrations now. And with the forthcoming (now available in 500 Epicor Functions it is even better)
I don’t put the code in a custom action though because those are tricky to call from Rest, I just put the code on Update.


Yes, I have a custom action built into the BAQ. I have the user execute this custom action through a customized dashboard. Instead of clicking Actions > Run Custom Action, they can just click the big button in the middle of the screen. The custom action does include BO methods, but it also contains some customized code. As a side note, in order to get the custom action to work well, I had to add an empty directive in the update method.
Good luck!

I’d like to do that. The current way I have it is pretty unmanageable and when i get a new web dev team looking at it, they go cross eyed with the complexity for some reason.

So for like “create order” id want the web app to pass basic info like sold to ship to bill to cust id , array of parts, etc. and the the ubaq to perform the transactions and return back an order num. doable in this method?

Yeah that’;s what we do, the UBAQ’s don’t really care what data you return or pass in what I usually end up doing is writing a BAQ that contains the data I want, then you are free to create your own equivalent “Record” and pass it to the Update.
The UBAQ doesn’t actually check or care that the BAQ didn’t return those results.
So you can baq a BAQ that has nothing but Calculated Empty fields and it will work just fine. But it is easier to use actual data, if nothing else to be lazy.
You will probably need 2 BAQ’s one for header and one for lines

1 Like

Now is the baq actually creating and updating records in like a ud table? Other method I was thinking is allocating a ud table for this and then the web app writes a new rec to it with Json in a field with all the info and the parse/transact with that data

The BAQ Itself in the Update Logic Creates the Sales Order Records.

so you’re saying the baq is built off the order hed table in this case?

It can be, like I said it doesn’t matter.
You can write a BAQ of the Company table (so you get 1 record) then add a bunch of empty calculated fields
Then in the UBAQ Update code you use these fields to create the sales order.

Via rest you do a PAtch -> ds{ Calculated_CustNum=34, Calculated_ShipTo=“Larry”} etc…

The UBAQ doesn’t care that those values didn’t come from the BAQ.
Though like I said it is usually easier to write the BAQ from the OrderHed table so you don’t have to create all those fields by hand.

Think of the BAQ Display Tab as your “Input data fields” You bring in the Order Hed table and “display” CustNum, ShipTo, Orderdate etc…
Then you fill those fields in with your data and do a Patch.

1 Like

is it possible to share this uBAQ ?

Unfortunately I have now combined this functionality into my end product. So I can’t share the whole thing. Post# 6 above has all the elements I needed to get the BAQ working. But there are a lot of other elements I had to put in place to be able to process the orders correctly. Do you need more info than what is listed in post 6?

i just want to see how do you pass ttValue’s and dataset between BO invoking widgets