cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Salamander94
Level: Powered On

Create a Button to Add User Information

So I've made an app for our small library.  I want to add a button to the detail screen for a quick checkout.  Right now users have to use the edit screen to add in their name and it'll mark the book as unavailable.  However, I'd love to have a button specifically for checking out and/or returning a book.  When they hit the button I want it to take their username and fill in the "Checked out By" field for them.  Then vice versa.   I thought the patch function would be all I needed.

Patch(IPC_LIB, ThisItem.'Checked Out By', User())

I'm probably just using the wrong syntax I assume.  Any suggestions?

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Create a Button to Add User Information

@Salamander94 

Yes, you can definitely do that and it will work.  However, given what we're looking at, you shouldn't have to do it since you're patching the datasource directly.  

However, you might want to change that formula just a bit...

Patch(IPC_LIB, 
BrowseGallery1.Selected,
{'Checked Out By' : If(IsBlank(BrowseGallery1.Selected.'Checked Out By'),User().FullName,"")}
);
Refresh(IPC_LIB);
Back()

Just taking out the logical AND operator you had in there and putting the refresh first. 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

23 REPLIES 23
Super User
Super User

Re: Create a Button to Add User Information

@Salamander94 

Assuming your 'Checkd Out By' column is a People column...

Try changing your Patch function to this formula:

Patch(IPC_LIB,
          ThisItem or Lookup, <- You need to specify the record you want to patch
          {
            'Checked Out By':
                { 
                 '@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser", 
                 Claims:"i:0#.f|membership|" & Lower(User().Email), 
                 Department:"", 
DisplayName:"",   Email:"",   JobTitle:"",  Picture:"" }
}
)

NOTE: the above you must specify the record you want to patch.  If you are in a Gallery that has the record from the datasource, then you can use ThisItem.  If you don't have it, then you will need to use a Lookup to get it -  Lookup(IPC_LIB, someColumn=someValue)  

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Salamander94
Level: Powered On

Re: Create a Button to Add User Information

Honestly, this went a bit over my head.  The "checked out by" was not a "person" column so I went ahead and made a column just called "check" that uses people.

Super User
Super User

Re: Create a Button to Add User Information

@Salamander94 

I had assumed your column was a Person column only because you were trying to assign User() to it.

If you want to patch a Person column, you need to specify the record as I showed in the formula example.  

If you want to patch a text column, you just need to change your User() to User().FullName (or one of the other values available on the User function)

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Community Support Team
Community Support Team

Re: Create a Button to Add User Information

Hi @Salamander94 ,

Do you want to add the "Check out" button within your Detail screen (display detail info of a specific book)?

Could you please share a screenshot about your app's configuration?

 

I assume that you use a Gallery control in your app to list all available books in your small library, and then within the Detail screen, display the detail info of a specific book selected from your Gallery, is it true?

 

Based on the formula that you mentioned, I think there is something wrong with it. I have made a test on my side, please take a try with the following workaround:

Within the Detail screen, set the OnSelect property of the "Quick Check out" button to following formula:

Patch(
          'YourDataSource',                   /* <-- 'YourDataSource' represents the data source to store your Library books in your app */
          BrowseGallery1.Selected,            /* <-- BrowseGallery1 represents the Gallery in your app to list all available books in your small library */
          {
             'Checked Out By': User().FullName
          }
)

Note: The 'Checked Out By' column is a Text type column in your data source.

 

In addition, you could also consider add a "Quick Return" button in your Detail screen, set the OnSelect property to following:

Patch(
          'YourDataSource',                   /* <-- 'YourDataSource' represents the data source to store your Library books in your app */
          BrowseGallery1.Selected,            /* <-- BrowseGallery1 represents the Gallery in your app to list all available books in your small library */
          {
             'Checked Out By': ""
          }
)

 

More details about the Patch function, please check the following article:

Patch function

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Salamander94
Level: Powered On

Re: Create a Button to Add User Information

So this check out and return button does work.  However, it seems like I have to click the button a few times in order for it to update on my screen then I get an error.

Capture.PNG

 

Super User
Super User

Re: Create a Button to Add User Information

@Salamander94 

Can you provide your current formula and also explain a little more about what you are expecting to have updated on the screen when you click the button. Also any other formulas you might have that are of any significance. 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Salamander94
Level: Powered On

Re: Create a Button to Add User Information

Okay so here is my detail screen:

Capture.PNG

Here is the code for "Check Out"

Patch(IPC_LIB,BrowseGallery1.Selected, {'Checked Out By': User().FullName})

Here is the code for "Return"

Patch(IPC_LIB,BrowseGallery1.Selected, {'Checked Out By': ""})

Now on the edit screen I had the "Available?" Field automatically update when someone entered their name or deleted their name.  Here's the code:

If(IsBlank(DataCardValue10), "Yes", "No")

Now I tried using this on the detail screen, but it does not update automatically like it did in the edit screen.  The only difference in the formula being the "datacardValue". 

 

So what seems to happen on the detail screen is when I hit the button once to check out, nothing updates.  If I hid it a second or third time it finally registers.  Same with the "Return" button but I still get that error message.  As I'd said before the "Available?" Field no longer updates within the detail and edit screen automatically either.

Here's the code for my browse gallerey:

SortByColumns(Filter(IPC_LIB, StartsWith(Title, TextSearchBox1.Text)), "Alphabatize", If(SortDescending1, Descending, Ascending))

Thanks for all your help and let me know what else, if anything, you need.

Salamander94
Level: Powered On

Re: Create a Button to Add User Information

In addition, ideally I just want the "check out" button to fill in their name to the "checked out by" field and then make the "Available?" field switch to no.  Vice versa I want the return button to delete their name and set the "Available?" field to "No".  It seems like the available field no longer updates on the gallerey either. 

Super User
Super User

Re: Create a Button to Add User Information

@Salamander94 

So, a couple things here:

You're using an Edit Form for this, so, you're going to need to submit it or refresh it since you are trying to do a Patch within it.  It makes me ask the question, do you need to do this Patch?  If you submit the form on your "Check Out" button instead, that would resolve some of this quicker.  This is a design choice, but I would consider having only one button.  It would change based on the value or lack of value in the 'Checked Out By' column:

Button Text Property:
    If(IsBlank(BrowseGallery1.Selected.'Checked Out By'), "Check Out, "Return")

The button would have a very simple action:

SubmitForm(yourFormName)

The Update Property of your DataCard for the 'Checked Out By' column would have the following:

If(IsBlank(ThisItem.'Checked Out By'), User().FullName, "")

As for the Available column...I would just base that off of the 'Checked Out By' value.  Not sure you really need it on the EditForm as it is not something that someone would change.  

If it is a column in your datasource, then you can set the Update Property of the DataCard for the Available column to the following:

If(IsBlank(ThisItem.'Checked Out By'), "Yes", "No")

This would take care of all the refreshing and updating and not require any Patch functions.

 

See what you think about that...

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (4,600)