Skip to main content
27 December 2023
Follow Us

Power Apps: How to create a Clock In app by scanning NFC tags [UPDATE]

As discussed in a previous post, today we're going to make an improved version of our clock in app. From the first version to this latest version, we've added another button and distinguished a specific NFC from the rest of the NFCs. In this post we'll cover the functionality of each of these new controls as well as the logic behind our application.

 

The New Button

With the creation of this button, we now have one button to record the entry and another to record the exit. In this way, you no longer need 2 NFC tags, as before. The code for each of the buttons is very similar, except that in the 'Entry/Exit' column, the entry button sends the text "ENTRY" to Sharepoint and the exit button sends the text "EXIT".
 
Entry Button
ForAll(NDEFRecords, Patch('Controlo de Ponto', Defaults('Controlo de Ponto'), {'Entrada/Saída': "ENTRADA", Title: User().FullName, Email: User().Email, 'Dia e Hora': Now()}));
 
Exit Button
ForAll(NDEFRecords, Patch('Controlo de Ponto', Defaults('Controlo de Ponto'), {'Entrada/Saída': "SAÍDA", Title: User().FullName, Email: User().Email, 'Dia e Hora': Now()}));
 

Personalised records

One of the upgrades made was to the gallery's entry/exit logs. In order to distinguish between entries made by the user and those made by other employees, it was decided to fill in the entries for the user in green. In other words, all my entries in the application will appear in green, while the rest of my colleagues will appear in the default white. Likewise, for another colleague who logs in with his account on his mobile device, the records that will appear in green are his own and not mine. In order to make this difference in the colour of the records, the following code was implemented:
 
If(ThisItem.Email = User().Email,
RGBA(54, 176, 75, 1),
RGBA(255, 255, 255, 1)
)
 

Reading a specific NFC

One problem that arose with the first version of the clock in app was that of reading NFCs. In the original version, the app needed to read a specific NFC for entry and another for exit. In order to be able to read with just one tag, it was necessary to specify which NFC tag to read. In order to fulfil this objective, it was necessary to update our code for the buttons, obtaining this result:
 
With(ReadNFC(),
Set(id, Coalesce(Identifier, "No ID"));
ForAll(NDEFRecords,
If(Coalesce(Text, URI) = "SWELL",
ForAll(NDEFRecords, Patch('Controlo de Ponto', Defaults('Controlo de Ponto'), {'Entrada/Saída': "ENTRADA", Title: User().FullName, Email: User().Email, 'Dia e Hora': Now()}));
)));
 
So what did we do? In short and simple terms, we created a condition. This evaluates whether the NFC tag has the Text or URI property equal to SWELL in its code.
If(Coalesce(Text, URI) = "SWELL",
 
Think of SWELL as the password for our NFC. If the condition is verified as true, then from that moment on we will map the fields in our Sharepoint list. If this condition doesn't hold, then the NFC reading will have no result.
 
By following these steps and making the necessary adjustments you should now have a clock in app, or an improved version of the previous one. The end result should look like this:
 
2
 
Rui Couto

Assine a nossa newsletter e receba o nosso conteúdo diretamente no seu email