@AndyPowerAppNew
So it will only sing out user if the staff name exists in the SP list ? Is that right ?
Yes my recent formula I gave that has the With function used in it, only signs out that specific person who is signed in, but you should have an additional Yes/No column called SignedIn for it to work. You should require the value, and put the default value to No if prompted on creation of this SharePoint column, to default to them not being signed in.
@AndyPowerAppNew wrote:
- I already have a column shows the user had singed in , will your code check that column ?
No that is the sign out date/time and you also have sign/in date time. Simply checking the presence of these columns is not a good idea. If you want to sign in or out again, how do you know they're signed in or out if they have already signed in and out once before? If you have already signed in and signed out before, you will have a date and time in both columns. Does that mean you're signed in, or signed out? It's ambiguous. So that's why you should have the additional SignedIn column with Yes/No choice to make it very clear.
You should change your Sign in button code to set them as signed in as well by setting the SignedIn to true upon sign in, like this:
With
(
{_myRecord:LookUp
(
StaffWhosIn
,'Employee Name' = User().FullName
)
}
,If
(
!IsBlank
(
_myRecord
,If
(
_myRecord.SignedIn
,Notify(_myRecord.'Employee Name' & " is already signed in",Error)
,Patch
(
StaffWhosIn
,{
ID: _myRecord.ID
,SignedIn: true
,SignInTimeDate: Now()
}
)
)
,Patch
(
StaffWhosIn
,{
'Employee Name' = User().FullName
,SignedIn: true
,SignInTimeDate: Now()
}
)
)
)
)
This formula only signs them in, if they are signed out. There is a difference though - if they really don't exist in this list yet, a new record is created for them. If they are already signed in, an error notification is displayed.
Similarly, for the formula I gave, it signs them out only if signed in. If you want to add a notification error if not signed in, do this for sign out:
With
(
{_myRecord:LookUp
(
StaffWhosIn
,'Employee Name' = User().FullName
)
}
,If
(
!IsBlank
(
_myRecord
,If
(
!_myRecord.SignedIn
,Notify(_myRecord.'Employee Name' & " is already signed out",Error)
,Patch
(
StaffWhosIn
,{
ID: _myRecord.ID
,SignedIn: false
,SignOutTimeDate: Now()
}
)
)
,Notify(_myRecord.'Employee Name' & " is signed out because they have never signed in",Error)
)
)
)
See if it helps @AndyPowerAppNew