cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Chameleon
Frequent Visitor

Staff Sign-in and out

Hi,

 

I've been playing with Powerapps the last couple of weeks and its been really fun except when I can't figure something out and I'm scrolling through miles of threads to find the one bit of code that might work or might not.

 

Anyway, at the moment I'm trying to make an app (for work Covid tracking an do away with a physical form).

I'm not even sure if it can be done as it seems too complicated in that it might be too hard to associate what row to pick when the user is showing on the list multiple times because they're expected to sign out whenever they leave the building (i.e for lunch or meetings etc.) and then sign in again when they return. Anyway, the way I want it is to have;

 

*A sign in button that when tapped signs them in (writes to a sharepoint list Name, time in, status in/out)

I would also like to have this button only visible if they haven't signed in (to avoid creating multiple 'in" rows and they know exactly if they have signed in or not).

 

*A sign out button that signs them out and writes to that same row time out and changes the status to out.

I would also only want this button to show if they are signed in and need to sign out.

 

Then the tricky bit is, I want them to be able to sign in again but create a new row when they do rather than modifying any of the existing rows.

 

In Sharepoint my columns are Title for name (Been using "(Text(User()Full.Name))" to fill the row), Time in , Time out, (both text fields been using "Text(Now(),"[$-en-GB]dd/mm/yyyy hh:mm:ss") and a choice column called Status which has In/Out.

 

I'm going to manually shift them all to a Daily list (or create a new Sharepoint file every night and change the apps source, whichever might be easier) to help keep the list slim.

 

Any help is very much appreciated. Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
v-qiaqi-msft
Community Support
Community Support

Hi @Chameleon,

Do you want to create a sign in and sign out button and write status back to SP list?

Could you please share a bit more about the scenario? 

I want to confirm with you that if you save all the info into a single SP list, I think you should create a new SharePoint file every night to help keep the list slim.

I have made a simple test for you, please take a try as below.

1). A sign in button that when tapped signs them in and have this button only visible if they haven't signed in.

Set the Visible of the sign in button as below:

If(IsBlank(LookUp(Tracking,User().Email in Name).Name),true,false)

Set the OnSelect of the sign in button as below:

If(
    IsBlank(
        LookUp(
            Tracking,
            User().Email in Name
        ).Name
    ),
    Patch(
        Tracking,
        Defaults(Tracking),
        {
            Name: User().Email,
            'Time in': Text(
                Now(),
                "[$-en-GB]dd/mm/yyyy hh:mm:ss"
            ),
            Status: {Value: "In"}
        }
    )
)

2). A sign out button that signs them out and show if they are signed in and need to sign out.

Set the Visible of the sign out button as below:

If(
    !IsBlank(
        LookUp(
            Tracking,
            User().Email in Name
        ).Name
    ) && CountRows(
        Filter(
            Tracking,
            User().Email in Name,
            Status.Value = "In"
        )
    ) > 0,
    true,
    false
)

Set the OnSelect of the sign out button as below:

If(
    CountRows(
        Filter(
            Tracking,
            User().Email in Name
        )
    ) = 1,
    Patch(
        Tracking,
        LookUp(
            Tracking,
            User().Email in Name
        ),
        {
            'Time out': Text(
                Now(),
                "[$-en-GB]dd/mm/yyyy hh:mm:ss"
            ),
            Status: {Value: "Out"}
        }
    ),
    If(
        CountRows(
            Filter(
                Tracking,
                User().Email in Name
            )
        ) > 1,
        Patch(
            Tracking,
            Last(
                Filter(
                    Tracking,
                    User().Email in Name
                )
            ),
            {
                'Time out': Text(
                    Now(),
                    "[$-en-GB]dd/mm/yyyy hh:mm:ss"
                ),
                Status: {Value: "Out"}
            }
        )
    )
)

3). Add another sign in button if you want to sign in again, set the Visible of this button as below:

If(Button_SignIn.Visible=false &&Button_SignOut.Visible=false,true,false)

 Set the OnSelect of this button as below:

Patch(
    Tracking,
    Defaults(Tracking),
    {
        Name: User().Email,
        'Time in': Text(
            Now(),
            "[$-en-GB]dd/mm/yyyy hh:mm:ss"
        ),
        Status: {Value: "In"}
    }
)

Hope it could help you at some degree.

Best Regards,
Qi

View solution in original post

2 REPLIES 2
v-qiaqi-msft
Community Support
Community Support

Hi @Chameleon,

Do you want to create a sign in and sign out button and write status back to SP list?

Could you please share a bit more about the scenario? 

I want to confirm with you that if you save all the info into a single SP list, I think you should create a new SharePoint file every night to help keep the list slim.

I have made a simple test for you, please take a try as below.

1). A sign in button that when tapped signs them in and have this button only visible if they haven't signed in.

Set the Visible of the sign in button as below:

If(IsBlank(LookUp(Tracking,User().Email in Name).Name),true,false)

Set the OnSelect of the sign in button as below:

If(
    IsBlank(
        LookUp(
            Tracking,
            User().Email in Name
        ).Name
    ),
    Patch(
        Tracking,
        Defaults(Tracking),
        {
            Name: User().Email,
            'Time in': Text(
                Now(),
                "[$-en-GB]dd/mm/yyyy hh:mm:ss"
            ),
            Status: {Value: "In"}
        }
    )
)

2). A sign out button that signs them out and show if they are signed in and need to sign out.

Set the Visible of the sign out button as below:

If(
    !IsBlank(
        LookUp(
            Tracking,
            User().Email in Name
        ).Name
    ) && CountRows(
        Filter(
            Tracking,
            User().Email in Name,
            Status.Value = "In"
        )
    ) > 0,
    true,
    false
)

Set the OnSelect of the sign out button as below:

If(
    CountRows(
        Filter(
            Tracking,
            User().Email in Name
        )
    ) = 1,
    Patch(
        Tracking,
        LookUp(
            Tracking,
            User().Email in Name
        ),
        {
            'Time out': Text(
                Now(),
                "[$-en-GB]dd/mm/yyyy hh:mm:ss"
            ),
            Status: {Value: "Out"}
        }
    ),
    If(
        CountRows(
            Filter(
                Tracking,
                User().Email in Name
            )
        ) > 1,
        Patch(
            Tracking,
            Last(
                Filter(
                    Tracking,
                    User().Email in Name
                )
            ),
            {
                'Time out': Text(
                    Now(),
                    "[$-en-GB]dd/mm/yyyy hh:mm:ss"
                ),
                Status: {Value: "Out"}
            }
        )
    )
)

3). Add another sign in button if you want to sign in again, set the Visible of this button as below:

If(Button_SignIn.Visible=false &&Button_SignOut.Visible=false,true,false)

 Set the OnSelect of this button as below:

Patch(
    Tracking,
    Defaults(Tracking),
    {
        Name: User().Email,
        'Time in': Text(
            Now(),
            "[$-en-GB]dd/mm/yyyy hh:mm:ss"
        ),
        Status: {Value: "In"}
    }
)

Hope it could help you at some degree.

Best Regards,
Qi

OMG! Thank you so much! Works perfectly!

I learned so much (whether I retain it or not is another thing). So many different formulas that didn't even cross my mind but make so much sense.

Thank you again! I'd pay you if I could! (I wouldn't, I'm poor, but I'd find something)

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (2,323)