Editar

Compartilhar via


Invoke a function from app, flow, code, or another function (preview)

[This topic is pre-release documentation and is subject to change.]

You can invoke functions in Dataverse from a canvas app, a custom page in a model-driven app, a flow, code, or from another function.

Important

  • This is a preview feature.
  • Preview features aren’t meant for production use and may have restricted functionality. These features are available before an official release so that customers can get early access and provide feedback.

Invoke a function from a canvas app or custom page

  1. From the Functions area in Power Apps (make.powerapps.com), select the function you want to invoke from a canvas app or custom page.
  2. Select Copy code snippet on the command bar.
  3. Paste and save the copied formula to a text editor, Notepad, or somewhere you can easily refer to.
  4. In Power Apps Studio:
    1. Create or edit a canvas app or custom page in Power Apps Studio.
    2. On the left navigation pane, under the Data Sources tab, select Add data, and search for the Environment option from the Dataverse connector, and select it.
    3. Insert the following components onto the canvas:
      • Add input controls that correspond with each parameter's data type, such as number input.
      • Add a button to call the function.
      • Add an output control that corresponds with your parameter's data type, such as number input.
  5. Select the button you created, and in the OnSelect property, enter your function, such as Environment.new_calculatesum.
  6. Map each input parameter Value to reference the corresponding input controls:
    • If your function is Environment.new_CalculateSum({ X: Value, Y: Value });, it could be rewritten as: Environment.new_CalculateSum({ X: NumberInput1.value, Y: NumberInput2.value });.
    • To set your Function 'result' output, update your formula to 'Set(result, Environment.new_CalculateSum({ X: NumberInput1.value, Y: NumberInput2.value }))'.
  7. Select the output control and set the 'Value' property with a formula of 'result.z'.

Preview your app, enter input 1 and 2 values, and select the button. The result should show in the output field.

Invoke functions from a Power Automate cloud flow

  1. In a cloud flow, add a new action from the Microsoft Dataverse connector.
  2. Select the action called Perform an unbound action
  3. Select your function. The function has a unique name with a prefix.
  4. Provide values for all the input parameters (if any).

Invoke functions from the Dataverse Web API

Follow the steps for the unbound action sections in the Invoking custom APIs from the Web API article (depending on the appropriate scope of the plug-in).

Invoke existing functions from within new functions

To invoke an existing function within a new function, use the syntax: Environment.ExistingFunction({inputParam1: value1, inputParam2: value2, ... inputParamN: valueN})

Since the output is always a record, use the dot notation to access the output parameters. For example, if the function "ExistingFunction" has two output parameters defined as out1 and out2, you can access them in either of these two ways:

  • Environment.ExistingFunction({inputParam1: value1, inputParam2: value2, ... inputParamN: valueN}).out1
  • Environment.ExistingFunction({inputParam1: value1, inputParam2: value2, ... inputParamN: valueN}).out2

Limitations with functions in Dataverse

  • The environment language object needs to be readded to access new functions inside existing canvas apps. For any functions created after you added the environment table data source to an existing canvas app, you must remove and readd the Power Fx environment language object. Then you see the updated list of functions as actions.
  • Nested support. functions can only call Microsoft actions published by Microsoft from Power Fx expressions.
  • Some Collect scenarios require Patch. There are some scenarios where Collect() doesn't work. The workaround is to use Patch() as shown in the populating regarding column example here.
Patch(Faxes,
       Collect(Faxes, {  Subject : "Sub1" } ),
       { Regarding : First(Accounts) }
    )

Debug and get help with your functions

If you encounter issues creating or running your function, use the trace() function for debugging or go to Limitations with functions in Dataverse for common issues that can occur.

Debugging using the trace() function

  1. To debug using the trace function, make sure that you enable plug-in and custom workflow activity tracking.
  2. Go to Power Apps (make.powerapps.com), select the Settings gear icon on the upper right, and then select Advance settings.
  3. Select Settings > Auditing > Global Audit Settings.
  4. On the Customization tab, ensure that Enable logging to plug-in trace log is enabled for All.

Once you enable tracking, you can start using trace() functions to debug Power Fx formulas. Learn more about how to use the trace() function inside a Power Fx expression: Trace function - Power Platform.

Contacting help + support

For issues with functions not covered in Microsoft Dataverse low-code plug-ins tips and known issues, such as undocumented errors received, use the Help + support experience and include the following information:

  • Problem Type- Dataverse Web API and SDK.
  • Problem Subtype.

Example functions

Create and use functions in Microsoft Dataverse