Hi Folks,
I have a problem in model driven apps I am trying to solve. I am still pretty new to Power Apps so I am having some trouble. Here is the use case.
I have a parent table called "Purchase Request" and a child table called "Purchase Request Item" where a user can put in a PR (purchase request) that can have many items in it. Since the items in a single PR may come from multiple vendors or may be funded from different funding streams, the purchaser is often required to break the PR into multiple orders. I have a parent table called "Order" and a child table called "Order Item".
I need the purchase to be able to open a PR, select one or more PR items from the sub-grid, then click a custom button, presumably on the sub-grid command bar, and have that OnSelect action do the following (if I am thinking through this correctly).
Create (patch) a new order in the "Order" table based on the data from the current PR
Get the newly created order's ID into a variable
Collect the selected PR items
Patch all the PR items in the collection to the "Order Item" table based on the data in the selected PR items and include the new patent order's ID in related column so that they show up as related
De-select the selected records in the PR item sub-grid.
Then the user should be able to select other PR items and create another new order repeating the process.
Additionally, I will need a strategy to select PR items and add them to an existing order in the event that the purchaser makes a mistake and forgets one, but first things first.
I have a custom button in the sub-grid command bar with the following OnSelect function.
Patch(
Orders,
Defaults(Orders),
{
GPRN:Self.Selected.Item.GPRN.GPRN,
ROM:"",
'Date Requested':Self.Selected.Item.GPRN.'Date Submitted',
'Date Needed':Self.Selected.Item.GPRN.'Date Required',
'Priority ':Self.Selected.Item.GPRN.Priority,
'Contract and Task Order':"",
PoP:"",
Project:"",
SLIN:""
}
)
This successfully creates the new order in the "Order" table, but I do not know how to capture the new order's id (OIDN). Can anyone help with this and the subsequent patching of the selected PR items to the "Order Item" table?
Please let me know if my description is unclear or further detail is needed.
Thanks and Kind Regards,
Patrick