Edit

Share via


Create and use functions in Microsoft Dataverse (preview)

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

Create and use reusable functions in Microsoft Dataverse. Functions use Power Fx to execute a specific set of commands within Dataverse that run server-side.

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.

Prerequisites

System customizer security role membership in the Power Platform environment.

Create a function in a solution

  1. Go to Power Apps, and then select Solutions in the left navigation pane. If the item isn’t in the side panel pane, select …More and then select the item you want.
  2. Open the solution where you want to create a function.
  3. On the command bar, select New > Automation > Function.
  4. Enter the following information in the New function side panel that appears.
    • Provide a Display name and Description for your function.
    • Select New input parameter and/or New output parameter, then provide a name and data type for the parameter. Add more input and output parameters as needed.
    • In the Table references list you can optionally select tables. You can reference the Dataverse tables you choose using data collection functions, such as Filter() and LookUp().
    • Enter the Power Fx expression in the Formula box.
  5. Select Save.
  6. Test the function.

Reference input parameters in the formula by their names.

Output parameters must be referenced inside of curly brackets, such as { Out: "Return value" }.

Tip

  • Notice the intellisense in the Formula box. Underlined red is invalid. Squiggly yellow means your logic might be affected by delegation limitations. Avoid delegation issues by using delegable functions.
  • Expand Advanced options to review your schema name.

Example functions

This section provides a few example functions.

Calculate the sum of two integers

  1. Enter a Display name, such as new_calculateSum, and a Description.

  2. Add two input parameters, x and y (both of data type integer), and one output parameter, z (data type integer).

  3. In the Formula box, enter the formula:
    { z:x+y }

    Function that multiplies two numbers.

  4. Test the function.

Add a new title to article table

  1. Create two input parameters title and url (both with string data types) and one output variable, message (data type string).
  2. Select the Knowledge Federated Articles table in the Table references dropdown.
  3. In the Formula box, enter the formula:
Collect('Knowledge Federated Articles',  
   { 
    Title: title, 
    URL: url 
    } 
    ); 
{ 
    message: "New Article title added: " & title 
}

Validate if an input string contains the strings of your choice

  1. Create an input parameter DocumentTextInput (with string data type) and one output variable, named result (data type string).
  2. In the Formula box, enter the formula:
{
    result: If("Confidentiality" in DocumentTextInput && "Dispute Resolution" in DocumentTextInput && "Governing Law" in DocumentTextInput && "Termination" in DocumentTextInput, 

    "Document is compliant.", 
    "Document is missing one or more compliance clauses." 
    ) 
}

Calculate a hotel stay price

  1. Create six input parameters: nights, rooms, tax, discount, roomservice, ratepernight (all with string data type) and one output variable, price (data type float).
  2. In the Formula box, enter the formula:
{ 
   price: ((nights*rooms*ratepernight)*(1+(tax/100))*(1-(discount/100)))+roomservice 

}

More function examples

For more example functions, go to Example functions (preview).

Edit, test, or delete a function

Edit a function

  1. Select your function in the Functions area.
  2. Select Edit on the command bar.
  3. Modify your formula, and then Save it.

Test a function

  1. Select the function in the Functions area.
  2. Select Test on the command bar.
  3. Provide values for the input parameters that are defined in the function, and then select Play.

A successful test returns an OData response that includes information such as the organization URI, function name, and output parameters and values.

Test a function

Tip

Use output parameters to help validate expected behavior and results. Otherwise, you only observe success or failure when testing.

Delete a function

Important

During the preview, don't delete your functions from the Solutions area as it might result in orphan components. Functions should be deleted by going to Power App (make.powerapps.com) > Functions on the left navigation pane.

  1. Select Functions on the left navigation pane, and then select your function. If the item isn’t in the side panel pane, select …More and then select the item you want.
  2. Select Delete on the command bar.

Functions in Microsoft Dataverse (preview)