Can someone explain to me why the orderRef variable is accessible to the union query but orderId is not? Running the entire query gives an error message "'where' operator: Failed to resolve scalar expression named 'orderId'"
** I know the second let assignment works as if I execute orderId with an orderId statement immediately following the first 2 let assignments I will get the orderId that I am looking to use in the final union query.
// <config>
let orderRef = "ABCDEF";
// </config>
// get orderId
let orderId = app('my-function').traces
| where message has orderRef
| order by timestamp asc
| extend msg=parse_json(substring(message, 6, strlen(message)))
| project msg.OrderId;
union *,
app('my-function').traces,
app('my-function2').traces,
app('my-function3').traces,
| where message has orderRef or message has orderId
| project timestamp, cloud_RoleName, operation_Name, message;
CodePudding user response:
let orderId = toscalar(app('my-function').traces
| where message has orderRef
| order by timestamp asc
| extend msg=parse_json(substring(message, 6, strlen(message)))
| project msg.OrderId);