skip to Main Content

I am creating a workbook in Azure where i am using KQL query and i have to dynamically pass resource groups values in the query from parameter.

From Parameter, resourcegroups are coming like

{ResourceGroups:label} ==> rg-abc-prod-westus, rg-xyz-ttt-westus

. There is a whitespace after , and before rg-xyz-ttt-westus

When i am using
let resourceGroupList = split("{ResourceGroups:label}",",")

the result is coming as ["rg-abc-prod-westus"," rg-xyz-ttt-westus"]

For the second resource group there is a whitespace between " and rg-xyz-ttt-westus.

Therefore in query, it is taking only first resource group.

I want like

["rg-abc-prod-westus","rg-xyz-ttt-westus"]

2

Answers


  1. You can use replace_regex() like below kql query:

    let tst = replace_regex("rg-abc-prod-westus, rg-xyz-ttt-westus",@"s","");
    let resourceGroupList = split(tst,",");
    print(resourceGroupList)
    

    Output:

    enter image description here

    Fiddle.

    Here, I have directly given array value, you can use the parameter for it and use the rest of function.

    Login or Signup to reply.
  2. fyi, the :label formatter for multi-value parameters returns all the content of the parameter as a single string as it is displayed in the UI instead of an array of values, so it could be like "a, b, c, +3 more" instead of "a", "b", "c", "d", "e", "f" like the real value is.

    it would be better to use the raw value directly, like

    let resourceGroups = todynamic([{ResourceGroups}]);
    

    so that resourceGroups is a real array of selected values, then you shouldn’t have to do any regex/etc and have a valid KQL array object you can use like

    | where whatatever in (resourceGroups)

    (and you can do other things like | where array_length(resourceGroups) == 0 or... to handle cases where nothing is selected, etc

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search