Hello, I am resuming an old Power Apps project that I had left aside. Being a beginner, I have a little trouble understanding some lines of code.
Can you please explain to me what this line of code does exactly (by detailing me each step of the line of code)? Thanks in advance !
If(varFilter = false ; Filter('Notes de frais'; StartsWith('Nom Prenom'.DisplayName; TextSearchBox1.Text) && 'Créé par'.Email=User().Email); Filter('Notes de frais'; StartsWith('Nom Prenom'.DisplayName; TextSearchBox1.Text)))
Hello @s44 , let me first format the expression in multiple lines:
1. If(
2. varFilter = false;
3. Filter(
3.1. 'Notes de frais';
3.2. StartsWith('Nom Prenom'.DisplayName; TextSearchBox1.Text) &&
3.3. 'Créé par'.Email=User().Email);
4. Filter(
4.1. 'Notes de frais';
4.2. StartsWith('Nom Prenom'.DisplayName; TextSearchBox1.Text)))
This is, line-by-line, what this expression is doing:
Another way to describe it: the expression will be all the records in the 'Notes de frais' data source, where the 'DisplayName' property of the 'Nom Prenom' field starts with the value in the TextSearchBox1; if the value of the 'varFilter' is set to false, then the result will have an additional filter where only the records created by the current user are returned.
Notice that the expression could be simplified, as pointed out by @WarrenBelz .
Hope this helps!
Hi @s44 ,
The logic seems backwards
If(
varFilter = false;
Filter(
'Notes de frais';
StartsWith(
'Nom Prénom'.DisplayName;
TextSearchBoxl.Text
) &&
'Créé par'.Email = User().Email
);
Filter(
'Notes de frais';
StartsWith(
'Nom Prénom'.DisplayName;
TextSearchBoxl.Text
)
)
)
and could be better written as
Filter(
'Notes de frais';
StartsWith(
'Nom Prénom'.DisplayName;
TextSearchBoxl.Text
) &&
(varFilter || 'Créé par'.Email = User().Email)
)
but you have a Data Source 'Notes de frais' which has a Person field 'Nom Prénom' that is filtered by TextSearchBox1 where the person's name needs to start with what is entered in there AND if a Variable called varFilter is false (this seems the reverse bit), then also filter on the Person field 'Créé par' where their email address matches that of the logged-in user.
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.
Visit my blog Practical Power Apps
WarrenBelz
146,660
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,999
Most Valuable Professional