I am trying to understand when 'As' is used inside With or ForAll, is it a creation of separate variable or just a pointer to data in the source? Below is an example (let's say there is a button on a screen with code below in OnSelect of the button):
ClearCollect(IceCreamSales,
Table(
{ Flavor: "Strawberry", UnitPrice: 1.99, QuantitySold: 20 },
{ Flavor: "Chocolate", UnitPrice: 2.99, QuantitySold: 45 },
{ Flavor: "Vanilla", UnitPrice: 1.50, QuantitySold: 35 }
)
);
With({X:LookUp(IceCreamSales,Flavor="Vanilla")},
With({P:X.UnitPrice},
Set(varBefore,X);
UpdateIf(IceCreamSales As K, K.Flavor=X.Flavor, {UnitPrice: K.UnitPrice+1.00});
Set(varAfter,LookUp(IceCreamSales,Flavor="Vanilla"));
Set(varPrice,P)
)
)
After clicking the button first time, I expect:
varBefore = {Flavor: "Vanilla", UnitPrice: 1.50, QuantitySold: 35}
varAfter = {Flavor: "Vanilla", UnitPrice: 2.50, QuantitySold: 35}
varPrice = 1.50
But what I get is:
varBefore = {Flavor: "Vanilla", UnitPrice: 2.50, QuantitySold: 35}
varAfter = {Flavor: "Vanilla", UnitPrice: 2.50, QuantitySold: 35}
varPrice = 1.50
This makes me think that X is just a pointer to the row containing Flavor="Vanilla"; otherwise the varBefore should have had the old price.
And in case of varPrice, it keeps the old price as what I expected, that means it is instantiated variable and not a pointer.
I'll appreciate any feedback