You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -108,3 +112,137 @@ After the previous formulas have been evaluated, the data source ends with these
108
112
| --- | --- | --- |
109
113
|**Patch( { Name: "James", Score: 90 }, { Name: "Jim", Passed: true } )**|Merges two records outside of a data source:<br><ul><li>The values in the **Name** column of each record don't match. The result contains the value (**Jim**) in the record that's closer to the end of the argument list instead of the value (**James**) in the record that's closer to the start.</li><li>The first record contains a column (**Score**) that doesn't exist in the second record. The result contains that column with its value (**90**).</li><li>The second record contains a column (**Passed**) that doesn't exist in the first record. The result contains that column with its value (**true**). |{ Name: "Jim", Score: 90, Passed: true } |
110
114
115
+
### Use of **As** or **ThisRecord**
116
+
Avoid an ambiguous evaluation context by using the **As** or **ThisRecord** keyword.
117
+
118
+
In the example below, consider the first Lookup in the If statement. (OrderID = A[@OrderID]) is expected to compare the OrderId in the Lookup scope with the OrderId of collection A in the ForAll scope. In this case, you likely want A[@OrderId] to be resolved as a local parameter. But it is ambiguous.
119
+
120
+
Power Apps currently interprets both the LHS side OrderId and RHS side A[@OrderId] as a field in the Lookup scope. Therefore, Lookup will always find the first row in [dbo].[Orders1] because the condition is always true (i.e., any row's OrderId is equal to itself.)
121
+
122
+
```powerapps-dot
123
+
ClearCollect(
124
+
A,
125
+
Filter(
126
+
'[dbo].[Orders1]',
127
+
OrderId = 8888888
128
+
)
129
+
);
130
+
ForAll(
131
+
A,
132
+
If(
133
+
LookUp(
134
+
'[dbo].[Orders1]',
135
+
OrderId = A[@OrderId],
136
+
"OK"
137
+
) = "OK",
138
+
Patch(
139
+
'[dbo].[Orders1]',
140
+
LookUp(
141
+
'[dbo].[Orders1]',
142
+
OrderId = A[@OrderId]
143
+
),
144
+
{
145
+
OrderName: "val1"
146
+
}
147
+
),
148
+
Patch(
149
+
'[dbo].[Orders1]',
150
+
Defaults('[dbo].[Orders1]'),
151
+
{
152
+
OrderName: "val2"
153
+
}
154
+
)
155
+
)
156
+
)
157
+
```
158
+
159
+
#### Using **As** or **ThisRecord**
160
+
161
+
Whenever possible use the **As** operator or the **ThisRecord** to disambiguate the LHS. **As** is recommended for the above scenario.
162
+
163
+
When your formula uses multiple scopes with ForAll, Filter, Lookup on the same data source or table, it is possible that the scope parameters may collide with a same named field elsewhere. Therefore, it is also recommended to use the **As** operator or **ThisRecord** to resolve the field name and avoid ambiguity.
164
+
165
+
For example, we can use the **As** operator to disambiguate in the example below.
166
+
167
+
```powerapps-dot
168
+
ClearCollect(
169
+
A,
170
+
Filter(
171
+
'[dbo].[Orders1]',
172
+
OrderId = 8888888
173
+
)
174
+
);
175
+
ForAll(
176
+
A,
177
+
If(
178
+
LookUp(
179
+
'[dbo].[Orders1]' As B,
180
+
B.OrderId = A[@OrderId],
181
+
"OK"
182
+
) = "OK",
183
+
Patch(
184
+
'[dbo].[Orders1]',
185
+
LookUp(
186
+
'[dbo].[Orders1]' As C,
187
+
C.OrderId = A[@OrderId]
188
+
),
189
+
{
190
+
OrderName: "val1"
191
+
}
192
+
),
193
+
Patch(
194
+
'[dbo].[Orders1]',
195
+
Defaults('[dbo].[Orders1]'),
196
+
{
197
+
OrderName: "val2"
198
+
}
199
+
)
200
+
)
201
+
)
202
+
```
203
+
204
+
Alternatively, we can use **ThisRecord** for the same purpose.
205
+
206
+
```powerapps-dot
207
+
ClearCollect(
208
+
A,
209
+
Filter(
210
+
'[dbo].[Orders1]',
211
+
OrderId = 8888888
212
+
)
213
+
);
214
+
ForAll(
215
+
A,
216
+
If(
217
+
LookUp(
218
+
'[dbo].[Orders1]',
219
+
ThisRecord.OrderId = A[@OrderId],
220
+
"OK"
221
+
) = "OK",
222
+
Patch(
223
+
'[dbo].[Orders1]',
224
+
LookUp(
225
+
'[dbo].[Orders1]',
226
+
ThisRecord.OrderId = A[@OrderId]
227
+
),
228
+
{
229
+
OrderName: "val1"
230
+
}
231
+
),
232
+
Patch(
233
+
'[dbo].[Orders1]',
234
+
Defaults('[dbo].[Orders1]'),
235
+
{
236
+
OrderName: "val2"
237
+
}
238
+
)
239
+
)
240
+
)
241
+
```
242
+
For detailed usage of the **As** operator and **ThisRecord**. For details, please see the **[Operators](operators.md)** article.
0 commit comments