How to use referencing functions inside a viewDefintion of a Managed App

Steven Hardy 0 Reputation points
2025-04-29T10:45:53.8966667+00:00

In our managed app, we deploy and manage an nva resource. In the createUiDefinition, we make use of Microsoft.Solutions.ArmApiControl to fetch the available versions for a given nva sku, so the user can select it via a Microsoft.Common.Dropdown. The "path" for the ArmApiControl requires the subscription id, which can be gotten via the reference function "subscription().id" then concat into the final desired path.

This works fine for the main createUiDefinition.

In our viewDefinition, we have added custom "commands" buttons that open up they're own CreateUiDef's, to allow the user to update the deployed resource to a different version. We want to be able to show the same dropdown in this view, however it seems that all the reference functions do not work, and subscription().id is empty.

Simplified create ui definition that works (dropdown shows available nva versions for first arbirtrary sku):

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {}
    ],
    "steps": [
      {
        "name": "step1",
        "label": "Step 1",
        "elements": [
          {
            "name": "details",
            "type": "Microsoft.Solutions.ArmApiControl",
            "toolTip": "The versions of the current sku.",
            "request": {
              "method": "GET",
              "path": "[concat(subscription().id, '/providers/Microsoft.Network/networkVirtualApplianceSkus?api-version=2024-07-01')]"
            }
          },
          {
            "name": "version",
            "type": "Microsoft.Common.DropDown",
            "label": "Version",
            "defaultValue": "[first(coalesce(first(steps('step1').details.value), parse('{\"properties\":{}}')).properties.availableVersions)]",
            "constraints": {
              "allowedValues": "[map(coalesce(first(steps('step1').details.value), parse('{\"properties\":{}}')).properties.availableVersions, (version) => parse(concat('{\"label\":\"',version,'\",\"value\":\"',version,'\"}')))]",
              "required": true
            },
            "visible": true
          }
        ]
      }
    ],
    "outputs": {
      "version": "[steps('step1').version]"
    }
  }
}

Simplified viewDefinition that does not work (exact same dropdown but in the "update" action button):

{
  "$schema": "https://schema.management.azure.com/schemas/viewdefinition/0.0.1-preview/ViewDefinition.json#",
  "contentVersion": "0.0.0.1",
  "views": [
    {
      "kind": "Overview",
      "properties": {
        "header": " ",
        "commands": [
          {
            "path": "update",
            "displayName": "Update",
            "icon": "Polychromatic.Gear",
            "createUIDefinition": {
              "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
              "handler": "Microsoft.Azure.CreateUIDef",
              "version": "0.1.2-preview",
              "parameters": {
                "steps": [
                  {
                    "name": "step1",
                    "label": "Step 1",
                    "elements": [
                      {
                        "name": "details",
                        "type": "Microsoft.Solutions.ArmApiControl",
                        "toolTip": "The versions of the current sku.",
                        "request": {
                          "method": "GET",
                          "path": "[concat(subscription().id, '/providers/Microsoft.Network/networkVirtualApplianceSkus?api-version=2024-07-01')]"
                        }
                      },
                      {
                        "name": "version",
                        "type": "Microsoft.Common.DropDown",
                        "label": "Version",
                        "defaultValue": "[first(coalesce(first(steps('step1').details.value), parse('{\"properties\":{}}')).properties.availableVersions)]",
                        "constraints": {
                          "allowedValues": "[map(coalesce(first(steps('step1').details.value), parse('{\"properties\":{}}')).properties.availableVersions, (version) => parse(concat('{\"label\":\"',version,'\",\"value\":\"',version,'\"}')))]",
                          "required": true
                        },
                        "visible": true
                      }
                    ]
                  }
                ],
                "outputs": {
                  "properties": {
                    "version": "[steps('step1').version]"
                  }
                }
              }
            }
          }
        ]
      }
    }
  ]
}
Azure Managed Applications
Azure Managed Applications
An Azure service that enables managed service providers, independent software vendors, and enterprise IT teams to deliver turnkey solutions through the Azure Marketplace or service catalog.
167 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Naveena Patlolla 1,895 Reputation points Microsoft External Staff
    2025-04-30T13:43:23.9933333+00:00

    Hi Steven Hardy

    Understanding the Scope of Referencing Functions:

    Referencing functions such as subscription(), resourceGroup(), location(), basics(), and steps() are designed to operate within the context of the main createUiDefinition.json file. These functions rely on the deployment context established during the creation of the managed application. When you define a nested createUiDefinition within a viewDefinition.json, the context may not be fully established, leading to the unavailability or incorrect evaluation of these functions.

     Limitations in viewDefinition.json:

    The viewDefinition.json file allows you to customize the managed application's overview and other views. However, it operates separately from the main createUiDefinition.json and does not inherently have access to the same deployment context. As a result, referencing functions that depend on deployment context may not function as expected within viewDefinition.json.

    Potential Workarounds:

    While there is no direct support for referencing functions within viewDefinition.json, you can consider the following approaches:

    1.Pass Parameters Explicitly: Instead of relying on referencing functions, pass the necessary parameters explicitly from the main createUiDefinition.json to the nested createUiDefinition within the viewDefinition.json. This approach ensures that the required values are available without depending on the evaluation of referencing functions.

     2.Use Static Values: If the values for the dropdown options are known and unlikely to change, you can hardcode them into the nested createUiDefinition. This eliminates the need for dynamic evaluation but reduces flexibility.

     3.Implement Custom Logic: Develop custom logic within your application to handle the dynamic fetching of values. This might involve using Azure Functions or other services to retrieve the necessary data and pass it to the UI components.

     The inability to use referencing functions within viewDefinition.json is a known limitation due to the separate evaluation contexts of the main createUiDefinition.json and viewDefinition.json. To work around this, consider passing parameters explicitly, using static values, or implementing custom logic to provide the necessary data to your UI components.

    Please let me know if you face any challenge here, I can help you to resolve this issue further
    Please do not forget to "Accept the answer” and “upvote it” wherever the information provided helps you, this can be beneficial to other community members.it would be greatly appreciated and helpful to others.

     


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.