In this episode our goal is to expose the SCR – Roll an Move flow to the right player on their Player record page. We use this page as the dashboard players 'work' from. Primarily because the Player record variable gives access to all the necessary input and information.
Putting a screen flow on a Lightning Page is in itself quite straight forward. However, what we want to accomplish is that players can only see and use the flow when it is their turn.
And for that, we first need to add a layer to our data model: Game. We're going to use this for several purposes.
- Players belong to one particular Game
- Within the Game, the players take turns in a fixed order
- The Game record should be able to indicate which player’s turn it is at any given moment
Further consequences of the Game object
Later on, we’ll also apply the Game framework to the rest of the data model.
- A board exists within one Game
- The Positions on that board therefore do too
- The Assets and Rules linked to those Positions also belong to a single Game
Let's make a comparison to the physical version of the game: every individual Game can be thought of as a different box containing a Board, tokens, Assets, Chance and Community Chest cards. Your token moves around the Board on the table where you and your friends are playing, not the next table. If you land on Chance, you get the top card from the pile that sits on your table, not the other party's table. Thge same goes for the Assets. Someone playing at another table may own all the train stations, but when you land on a station, you do not pay rent to them. They do not own any of the stations in your Game after all.
Those modifications will be for another time however. For this episode we just need the Game to tell whose turn it is.
Steps fo this episode
- We must create the Game object
- On the Game object, we need to create a lookup to Player. This represents the Player whose turn it currently is.
- We need to create a Lookup Relationship on the Player object to Game.
- We need to create a number field on the Player object that indicates the turn order of the different Players within the same Game.
- On the Player object, we need to create a formula that indicates whether this player is currently the one whose turn it is.
- We need to create a flow that looks up the next player whose turn it is and updates the Game record accordingly.
- That flow should be added at the very end of the SCR – Roll and Move flow as a subflow, because once one player's turn is finished, it needs to pass to the next player.
- The visibility of the SCR – Roll and Move flow should be made conditional. It should only appear on the Player page when it is that player's turn.
The Game object
In this series, we created most of the objects using Schema Builder. The advantage of this approach is that creating fields is much faster, but the downside is that you need to create tabs and page layouts afterwards.
This time, we're going to create the new object directly through the Object Manager.


In step 2, I choose to set the tab to Hidden for all profiles. After all, we’ve decided to grant access to the Monopoly app and its functionalities through the Permission Sets we created earlier.

In step 3, we add this new tab only to the Monopoly app, and not to any of the other apps.

We’re adding the Active Player lookup to the object. Since the lookup from Player to Game doesn’t exist yet, we can’t set up the lookup filter just yet. We’ll come back to that shortly.

For this field as well, we uncheck access for all profiles in step 4, since all access will be managed through the Permission Sets.

In step 5, we include this field in the default Page Layout for the Game object. In step 6, we uncheck the option to add the Games related list to the Player object, as we don't need it.
New fields on the Player object
We will create 3 new fields on the Player object
- Game – a lookup to the Game in which this Player is currently playing.
- Next, we'll add a lookup filter to the Player lookup we just created on the Game object.
- Playing Order – a number that indicates when a player's turn is
- It’s my turn now – een formule met output checkbox die aangevinkt is wanneer deze speler aan de beurt is.
Game lookup
Since we'll need to access the Game object again shortly, I'm opening a new tab with the Object Manager so I can keep the Game tab open.

Just like with every field we create for our Monopoly game, we won’t grant access to it in any of the profiles.
Unlike with the new Game object, we already have a Lightning Page for Player, so we’re allowed to add the new field to it—and that’s exactly what we’ll do.

We do want the Related List with Player on the Game object, so in step 7, make sure to leave the checkboxes selected.

Now we need to add these new lookup fields to our Permission Set before we can create the lookup filter.
Lookup filter
Now that the relationship from Player to Game also exists, we can add the lookup filter to the Game-to-Player relationship we just created.
A lookup filter is a condition that a record must meet in order to be selectable in that relationship field. A Player can only be marked as the current turn in a Game if that Player belongs to that Game.

In the example above, Anna, Boris, and Chloë—who are participating in Game 001—are allowed to be selected as the Active Player for Game 001. However, Duco, Eline, and Finn are not, as they are not part of that game. Conversely, for Game 002, only Duco, Eline, and Finn can be chosen as the Active Player, since they are the ones playing in that match.
To do this, go to Object Manager > Game > Fields & Relationships, open the Active Player field, and click Edit. Under the Lookup Filter section, click Show Filter Settings, and under Field, select: Current Lookup Active Player:

Then choose Game (note: the version without the :
at the end). Use the Equals operator, select Field under Value/Field, and then choose Game: Record ID. If desired, adjust the Error Message text and save using the Save button.

Playing Order
For this, we’ll simply create a basic Number field. 18 digits before and 0 after the decimal point is perfect. You can leave the other settings as they are.
Once again, we won’t grant access to the field through Profiles. However, the new field can be added right away to the Lightning Page and Page Layout.
It’s my turn now
We need this formula to determine whether the SCR – Roll and Move flow should be visible on the Player’s record page. The output of the formula is a checkbox. It should be checked, or True, when the ID of this Player matches the ID in the Active Player field of the Game the Player is part of. Like the other fields, it will appear on the Lightning Page and Page Layout, but not in any Profile.

The Permission Sets


Flow to start the next player's turn
This will be a simple autolaunched flow that we’ll insert at the end of the SCR – Roll and Move flow, allowing the turn to pass to the next player.

As with every subflow we've created so far for the SCR – Roll and Move flow, we’ll once again start by creating the input variable inputPlayer
.

First, we look for the next player within the same Game who has a higher number in the Playing Order field.
If the current active player has the highest Playing Order number within that Game, the first search won’t return anything, and we’ll need to use a different search. Since I only need the Player ID from one of the two searches, I want to store the result in a single variable. That’s why we don’t select Automatically store all fields under How to Store Record Data. This way, the variable nextPlayerId
will always contain the correct Player ID—regardless of whether it’s found in the first or the second search.

Let’s say we have three players—Anna, Boris, and Chloë—with Playing Orders 1, 2, and 3.
When it’s Anna’s turn, the left-hand search will return Boris’s ID.
At the end of Boris’s turn, the left-hand search will return Chloë’s ID.
At the end of Chloë’s turn, the left-hand search will return null, and we’ll use the right-hand search instead, which will lead us back to Anna.
Next, we can use an Update Records element to update the Game’s Active Player. There's no need for a null check here. If neither of the searches returns a Player, it means there are no Players at all or someone is playing solo—so in that case, the Game doesn’t need to have an Active Player.

Now we just need to save and activate this flow so we can insert it into the SCR – Roll and Move flow.

We’ll add this new flow at the very end of the SCR – Roll and Move flow.

Placing SCR – Roll and Move on the Player Lightning Page
In the Lightning App Builder, on the MON – LRP – Player page, you can search for Flow under Components in the left sidebar. Drag it onto the page. Configure it so that the data from the displayed record is passed to the flow’s input variable (recordId
), and set the component to be conditionally visible: the flow should only be shown when It’s my turn now is true.


Next time
Before we dive into how players can get out of jail, we’ll first make a small but helpful improvement in the next section. When setting the conditional visibility for certain sections and buttons, there’s a way to simplify things—and that’s what we’ll take care of first.