web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Patch to update inventory
Power Apps
Answered

Patch to update inventory

(0) ShareShare
ReportReport
Posted on by 6

I've created an app for a small library which allows staff to request up to four books at once. This is the code I have in for the request, which works fine:

 

 

Set(
varrecordid,
ForAll(
'Cart List'.AllItems,
Patch(
'Book Requests',
Defaults('Book Requests'),
{
Title: TextInput1_3.Text,
'Title(s)': ThisRecord.Title,
'Author(s)': ThisRecord.Author,
Delivery: Dropdown6_2.Selected.Value,
'CPFT Email Address': TextInput1_4.Text,
Address: Dropdown6_4.Selected.Value,
Team: TextInput1_5.Text,
'Due Date': DateValue(Label4_10),
'Selected Loan Period': Dropdown6_3.Selected.Value,
User: Text(varUserEmail),
'Loan Status': Text("On Loan"),
'Total Requesting': Value(TextInput1.Text)
}
).ID
)
);

 

 

but I'd also like the number of books available to decrease by one on the original sharepoint list (named 'Library App') when a book is requested. I can only work out how to do this if books were getting requested individually, but how would I update the inventory count for multiple records at once? I tried the below but it didn't like title=thisrecord.title (also this was from when I was testing to reset it to 0, when in reality I would like it to -1, but I couldn't quite work that out either!)

 

 

ForAll('Cart List'.AllItems, Patch('Library App', LookUp('Library App', Title=ThisRecord.Title), {'Copies available': 0}));

 

 

 

Categories:
  • WarrenBelz Profile Picture
    156,528 Most Valuable Professional on at

    Hi @lucyrobson ,

    You did not state your data source, but assuming SharePoint, this will also allow for multiple copies of a book

    Patch(
     'Library App',
     ForAll(
     'Cart List'.AllItems,
     With(
     {
     _Book:
     LookUp(
     'Library App', 
     Title = ThisRecord.Title
     )
     },
     {
     ID: _Book.ID,
     'Copies available': _Book.'Copies available' - 1
     }
     )
     )
    );

     

    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

  • lucyrobson Profile Picture
    6 on at

    Thanks for your reply @WarrenBelz! Yes, my data source is Sharepoint. I've just tried this but I'm getting the error message 'Error when trying to retrieve date from the network: Fetching items failed. Possible invalid string in filter query.' Looks like it still doesn't like title=thisrecord.title. Any ideas? 🙂

  • Verified answer
    WarrenBelz Profile Picture
    156,528 Most Valuable Professional on at

    @lucyrobson .

    OK - we will go with another syntax

    Patch(
     'Library App',
     ForAll(
     'Cart List'.AllItems As _Data,
     With(
     {
     _Book:
     LookUp(
     'Library App', 
     Title = _Data.Title
     )
     },
     {
     ID: _Book.ID,
     'Copies available': _Book.'Copies available' - 1
     }
     )
     )
    );

     

    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

  • lucyrobson Profile Picture
    6 on at

    That has worked, thank you so much! 🙂

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 409 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 252 Most Valuable Professional

Last 30 days Overall leaderboard