cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rosscortb
Helper III
Helper III

Patching to the sharepoint list

Hello,

 

Struggling to get this to work.

 

I have three sharepoint lists

Personal Detail.

Shopping Cart Orders(as a lookup)

Shopping Cart Order Items

 

 

I can get the OrderID from Shopping Cart Orders into Shopping Cart Order Items and Personal Details.

 

Set(varRecordID,Patch('Shopping Cart Orders',Defaults('Shopping Cart Orders'),{Title:Title1.Text},{Price:Lbl_Price.Text}).ID);


ForAll(Basket,Patch('Shopping Cart Order Items',Defaults('Shopping Cart Order Items'),{Title:Product},{OrderID:varRecordID},{PointsQuantity:PointsQuantity},{SalesQuantity:SalesQuantity},{Price:Price},{PointsPerBottle:PointsPerBottle},{Product:Product},{ProductID:Id}));

 

ForAll(PDetails,Patch('SBP Shop Order Personal Details',Defaults('SBP Shop Order Personal Details'),{'Name (Title)':'Name (Title)'},{'Employee Number':'Employee Number'},{'Department / Team':'Department / Team'},{'Nominated person to collect':'Nominated person to collect'},{'Nominated Person Email':'Nominated Person Email'},{'Deliver to location':'Deliver to location'},{'Nightshift Worker':'Nightshift Worker'},{Email:Email},{OrderID:varRecordID}))

 

 

I then want to add a lookup column in the Shopping Cart Order Items to bring through the employee name from the Personal Details sharepoint list so I can see who's name is against each order.

 

But the names are there but not auto populated. Is this possible please? Thanks Ross

 

rosscortb_0-1670583823699.png

 

 

rosscortb_1-1670583870110.png

 

 

7 REPLIES 7
WarrenBelz
Super User
Super User

Hi @rosscortb ,

Two things here before I get to your main question - you have potential ambiguity with identical field names on both sides of the Patches and also you have ForAll backwards. It is not designed to be a Loop, although it can work this way with considerable performance penalty as it does an individual Patch for each record. ForAll() creates a Table, which can be patched in one action provided its content is correct. For new records, this is simply a Table with field names and field types matching the list. 

I have included the lookup to your employee name as well - just add your field names.

Patch(
   'Shopping Cart Order Items',
   ForAll(
      Basket As aPatch,
      {
         Title: aPatch.Product,
         OrderID: varRecordID,
         PointsQuantity: aPatch.PointsQuantity,
         SalesQuantity: aPatch.SalesQuantity,
         Price: aPatch.Price,
         PointsPerBottle: aPatch.PointsPerBottle,
         Product: aPatch.Product,
         ProductID: aPatch.Id
      }
   )
);
Patch(
   'SBP Shop Order Personal Details',
   ForAll(
      PDetails As aPatch,
      {
         'Name (Title)': aPatch.'Name (Title)',
         'Employee Number': 
         LookUp(
            'Person Details',
            YourEmpNoField = aPatch.'Employee Number'
         ).YourNameField,
         'Department / Team': aPatch.'Department / Team',
         'Nominated person to collect': aPatch.'Nominated person to collect',
         'Nominated Person Email': aPatch.'Nominated Person Email',
         'Deliver to location': aPatch.'Deliver to location',
         'Nightshift Worker':aPatch.'Nightshift Worker'
         Email: aPatch.Email,
         OrderID: varRecordID
      }
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

MVP (Business Applications)   Visit my blog Practical Power Apps

@WarrenBelz Appreciate the help.

 

In your code should 'Person Details' be PDetails which is the collection?

 

 

Patch(
    'Shopping Cart Order Items',
    ForAll(
        Basket As aPatch,
        {
            Title: aPatch.Product,
            OrderID: varRecordID,
            PointsQuantity: aPatch.PointsQuantity,
            SalesQuantity: aPatch.SalesQuantity,
            Price: aPatch.Price,
            PointsPerBottle: aPatch.PointsPerBottle,
            Product: aPatch.Product,
            ProductID: aPatch.Id
        }
    )
);
Patch(
    'SBP Shop Order Personal Details',
    ForAll(
        PDetails As aPatch,
        {
            'Name (Title)': aPatch.'Name (Title)',
            'Employee Number': LookUp(
                PDetails,
                'Employee Number' = aPatch.'Employee Number'
            ).'Employee Number',
            'Department / Team': aPatch.'Department / Team',
            'Nominated person to collect': aPatch.'Nominated person to collect',
            'Nominated Person Email': aPatch.'Nominated Person Email',
            'Deliver to location': aPatch.'Deliver to location',
            'Nightshift Worker': aPatch.'Nightshift Worker',
            Email: aPatch.Email,
            OrderID: varRecordID
        }
    )
)

 

 

I managed to get this to work but it doesn't bring in the OrderID, where do I set that please?

 

Update: Actually have set it the gallery so not sure why is not pulled through....

rosscortb_0-1670839794348.png

 

 

Thanks
Ross

@rosscortb ,

PDetails was from your code posted, but yes, it would be a collection.

@WarrenBelz Thanks, any ideas why I can't get the OrderID returned?

 

rosscortb_0-1670847125403.png

As mentioned above, I have the variable set against ThisItemId.

 

Thanks again.

 

Ross

@rosscortb ,

You are using varRecord.ID to obtain this - the first place would be to put this on a Label and see if is the correct value before you trigger the Patch. You are setting it here, which should work

Set(
   varRecordID,
   Patch(
      'Shopping Cart Orders',
      Defaults('Shopping Cart Orders'),
      {
         Title: Title1.Text,
         Price: Lbl_Price.Text
      }
   ).ID
);

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

MVP (Business Applications)   Visit my blog Practical Power Apps

 

@WarrenBelz I can see the varRecordID in the label.

 

Appreciate the help, got OrderID showing in both list but can't see how the relationship is created by employee and ordered item as when I add a lookup in the list to bring employee name through to ordered items, I get options. Order 95 should be against John.

rosscortb_0-1670851604798.png

 

Thanks Ross

@rosscortb ,

I posted this

'Employee Number':
LookUp(
   'Person Details',
   YourEmpNoField = aPatch.'Employee Number'
).YourNameField,

which you changed to this

'Employee Number': 
LookUp(
   PDetails,
   'Employee Number' = aPatch.'Employee Number'
).'Employee Number',

What you need to do is match the employee number from your 'Person Detail' list with whatever field in the order matches it and find the name. Please take a moment to understand the logic of this an I am sure you will find the right value.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

MVP (Business Applications)   Visit my blog Practical Power Apps

 

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,213)