适用于: Azure 逻辑应用(消耗型 + 标准型)

对于 Azure 逻辑应用 Power Automate 中的工作流定义,某些 表达式 获取的值来自运行时操作,而这些运行时操作在工作流开始运行时可能尚不存在。 To reference or process the values in these expressions, you can use expression functions provided by the Workflow Definition Language .

本参考指南适用于 Azure 逻辑应用和 Power Automate,但存在于 Azure 逻辑应用文档中。 尽管本指南特别提到逻辑应用工作流,但这些函数适用于 Power Automate 中的流和 Azure 逻辑应用中的工作流。 有关 Power Automate 中的函数和表达式的详细信息,请参阅 在条件中使用表达式

For example, you can calculate values by using math functions, such as the add() function, when you want the sum from integers or floats. 下面是可以使用函数执行的一些其他示例任务:

Function syntax Result

若要 基于函数的常规用途 查找函数,请查看以下各表。 Or, for detailed information about each function, see the alphabetical list .

表达式中的函数

To show how to use a function in an expression, this example shows how you can get the value from the customerName parameter and assign that value to the accountName property by using the parameters() function in an expression:

"accountName": "@parameters('customerName')"

下面是表达式中的函数的其他一般使用方法:

表达式中的函数语法 1. Get the parameterName's value by using the nested parameters() function.
2. Perform work with the result by passing that value to functionName. "@<functionName>(parameters('<parameterName>'))" 1. Get the result from the nested inner function functionName.
2. Pass the result to the outer function functionName2. "@<functionName2>(<functionName>(<item>))" 1. Get the result from functionName.
2. Given that the result is an object with property propertyName, get that property's value. "@<functionName>(<item>).<propertyName>"

例如,concat() 函数可以采用两个或更多个字符串值作为参数。 此函数将这些字符串组合成一个字符串。 可以传入字符串文字(例如 "Sophia" 和 "Owen"),以便获取组合的字符串 "SophiaOwen":

"customerName": "@concat('Sophia', 'Owen')"

或者,可以从参数获取字符串值。 此示例在每个 parameters() 参数以及 concat()firstName 参数中使用 lastName 函数。 然后,将生成的字符串传递给 concat() 函数,以便获取组合的字符串,例如 "SophiaOwen":

"customerName": "@concat(parameters('firstName'), parameters('lastName'))"

无论使用哪种方式,这两个示例都会将结果分配给 customerName 属性。

使用函数的注意事项

  • 设计器不会计算在设计时用作函数参数的运行时表达式。 设计器要求在设计时可以完全计算所有表达式。

  • 从左到右评估函数参数。

  • 在参数定义的语法中,参数后显示的问号 (?) 表示参数是可选的。 For example, see getFutureTime().

  • 以纯文本内联显示的函数表达式需要使用封闭的大括号 ({}) 以使用表达式的内插格式。 此格式有助于避免分析问题。 如果函数表达式没有以纯文本内联显示,则无需大括号。

    以下示例显示了正确和不正确的语法:

    Correct: "<text>/@{<function-name>('<parameter-name>')}/<text>"

    Incorrect: "<text>/@<function-name>('<parameter-name>')/<text>"

    OK: "@<function-name>('<parameter-name>')"

    The following sections organize functions based on their general purpose, or you can browse these functions in alphabetical order.

    String functions

    To work with strings, you can use these string functions and also some collection functions. 字符串函数仅适用于字符串。

    String function

    逻辑比较函数

    若要使用条件、比较值和表达式结果或评估各种类型的逻辑,可以使用这些逻辑比较函数。 For the full reference about each function, see the alphabetical list.

    如果使用逻辑函数或条件来比较值,则 NULL 值将转换为空字符串 ("") 值。 与空字符串(而不是 NULL 值)进行比较时,条件的行为会有所不同。 For more information, see the string() function.

    Conversion functions

    若要更改值的类型或格式,可以使用这些转换函数。 例如,可将值从布尔值更改为整数。 有关 Azure 逻辑应用在转换期间如何处理内容类型的详细信息,请参阅处理内容类型。 For the full reference about each function, see the alphabetical list.

    Azure 逻辑应用会自动或隐式执行 base64 编码和解码,因此你无需使用编码和解码函数手动执行这些转换。 但是,如果你仍然在设计器中使用这些函数,则可能会在设计器中遇到意外的呈现行为。 这些行为仅影响函数的可见性,而不影响其效果,除非你编辑函数的参数值,这样会从代码中删除函数及其效果。 有关详细信息,请参阅隐式数据类型转换

    隐式数据类型转换

    Azure 逻辑应用会自动或隐式地在某些数据类型之间进行转换,因此你无需手动执行这些转换。 例如,如果在预期应输入字符串的情况下输入了非字符串值,则 Azure 逻辑应用会自动将非字符串值转换为字符串。

    例如,假设触发器返回一个数值作为输出:

    triggerBody()?['123']

    如果在需要字符串作为输入(如 URL)的地方使用了此数值输出值,则 Azure 逻辑应用会使用大括号 ({}) 表示法自动将该值转换为字符串:

    @{triggerBody()?['123']}

    Base64 编码和解码

    Azure 逻辑应用会自动或隐式执行 base64 编码或解码,因此你无需使用相应的函数手动执行这些转换:

  • base64(<value>)
  • base64ToBinary(<value>)
  • base64ToString(<value>)
  • base64(decodeDataUri(<value>))
  • concat('data:;base64,',<value>)
  • concat('data:,',encodeUriComponent(<value>))
  • decodeDataUri(<value>)
  • 如果你在使用设计器时手动添加任何这些函数(直接添加到触发器或操作中或者使用表达式编辑器),则请先离开设计器,然后再返回到设计器,这样该函数就会从设计器中消失,只留下参数值。 如果你选择一个使用此函数的触发器或操作而不编辑函数的参数值,则也会出现此行为。 此结果只影响函数的可见性,而不影响效果。 在代码视图中,函数不受影响。 但是,如果你编辑函数的参数值,则会从代码视图中删除函数及其效果,而只留下函数的参数值。

    Math functions

    若要使用整数和浮点数,可以使用这些数学函数。 For the full reference about each function, see the alphabetical list.

    Math function

    Return the current action's output at runtime, or values from other JSON name-and-value pairs, which you can assign to an expression. 默认情况下,此函数引用整个操作对象,但是也可以指定你需要其值的属性。 See also actions().

    只能在以下位置使用 action() 函数:

  • Webhook 操作的 unsubscribe 属性,用以访问原始 subscribe 请求的结果
  • 操作的 trackedProperties 属性
  • 操作的 do-until 循环条件
  • action()
    action().outputs.body.<property>
    

    actions

    返回操作在运行时的输出,或者来自其他 JSON 名称和值对的值,可以将其分配给表达式。 默认情况下,此函数引用整个操作对象,但是也可以指定你需要其值的属性。 For shorthand versions, see body(). For the current action, see action().

    actions() 函数以字符串的形式返回输出。 如果需要将返回值用作 JSON 对象,则首先需要转换字符串值。 可以使用分析 JSON 操作将字符串值转换为 JSON 对象。

    以前,当指定基于另一操作的输出运行的操作时,可以使用 actions() 函数或 conditions 元素。 但是,若要显式声明操作之间的依赖关系,现在必须使用依赖的操作的 runAfter 属性。 若要详细了解 runAfter 属性,请参阅使用 runAfter 属性捕获和处理故障

    actions('<actionName>')
    actions('<actionName>').outputs.body.<property>
                  Example 1

    This example adds the middleName property to a JSON object, which is converted from a string to JSON by using the JSON() function. 该对象已经包含 firstNamesurName 属性。 该函数将指定的值分配给新属性,并返回更新后的对象:

    addProperty(json('{ "firstName": "Sophia", "lastName": "Owen" }'), 'middleName', 'Anne')
    

    下面是当前的 JSON 对象:

    "firstName": "Sophia", "surName": "Owen"

    下面是已更新的 JSON 对象:

    "firstName": "Sophia", "middleName": "Anne", "surName": "Owen" Example 2

    This example adds the middleName child property to the existing customerName property in a JSON object, which is converted from a string to JSON by using the JSON() function. 该函数将指定的值分配给新属性,并返回更新后的对象:

    setProperty(json('{ "customerName": { "firstName": "Sophia", "surName": "Owen" } }'), 'customerName', addProperty(json('{ "customerName": { "firstName": "Sophia", "surName": "Owen" } }')['customerName'], 'middleName', 'Anne'))
    

    下面是当前的 JSON 对象:

    "customerName": { "firstName": "Sophia", "surName": "Owen"

    下面是已更新的 JSON 对象:

    "customerName": { "firstName": "Sophia", "middleName": "Anne", "surName": "Owen"

    addSeconds

    将秒添加到时间戳。

    addSeconds('<timestamp>', <seconds>, '<format>'?)
    
    addToTime('2018-01-01T00:00:00Z', 1, 'Day', 'D')
    

    并使用可选的“D”格式返回结果:"Tuesday, January 2, 2018"

    检查所有表达式是否为真。 当所有表达式均为 true 时返回 true,当至少一个表达式为 false 时返回 false。

    and(<expression1>, <expression2>, ...)
    
  • 第一个示例:两个表达式均为 true,因此返回 true
  • 第二个示例:一个表达式为 false,因此返回 false
  • 第三个示例:两个表达式均为 false,因此返回 false
  • Example 2

    这些示例检查指定的表达式是否均为 true:

    and(equals(1, 1), equals(2, 2))
    and(equals(1, 1), equals(1, 2))
    and(equals(1, 2), equals(1, 3))
    

    并返回以下结果:

  • 第一个示例:两个表达式均为 true,因此返回 true
  • 第二个示例:一个表达式为 false,因此返回 false
  • 第三个示例:两个表达式均为 false,因此返回 false
  • 从单个指定的输入返回数组。 For multiple inputs, see createArray().

    array('<value>')
    

    Azure 逻辑应用会自动或隐式执行 base64 编码和解码,因此你无需使用编码和解码函数手动执行这些转换。 但是,如果你仍然使用这些函数,则可能会在设计器中遇到意外的呈现行为。 这些行为仅影响函数的可见性,而不影响其效果,除非你编辑函数的参数值,这样会从代码中删除函数及其效果。 有关详细信息,请参阅 Base64 编码和解码

    base64('<value>')
    

    Azure 逻辑应用会自动或隐式执行 base64 编码和解码,因此你无需使用编码和解码函数手动执行这些转换。 但是,如果你仍然在设计器中使用这些函数,则可能会在设计器中遇到意外的呈现行为。 这些行为仅影响函数的可见性,而不影响其效果,除非你编辑函数的参数值,这样会从代码中删除函数及其效果。 有关详细信息,请参阅 Base64 编码和解码

    base64ToBinary('<value>')
    
    base64ToBinary('aGVsbG8=')
    

    例如,假设你正在使用 HTTP 操作发送请求。 你可以使用 base64ToBinary() 将 base64 编码字符串转换为二进制数据,并使用请求中的 application/octet-stream 内容类型发送该数据。

    base64ToString

    返回 base64 编码字符串的字符串版本,有效地对 base64 字符串进行解码。 Use this function rather than decodeBase64(), which is deprecated.

    Azure 逻辑应用会自动或隐式执行 base64 编码和解码,因此你无需使用编码和解码函数手动执行这些转换。 但是,如果你仍然在设计器中使用这些函数,则可能会在设计器中遇到意外的呈现行为。 这些行为仅影响函数的可见性,而不影响其效果,除非你编辑函数的参数值,这样会从代码中删除函数及其效果。 有关详细信息,请参阅 Base64 编码和解码

    base64ToString('<value>')
                  Example

    例如,使用返回图像或视频文件的 HTTP 操作。 可使用 binary() 将该值转换为 base-64 编码的内容信封模型。 然后,你可以在其他操作(例如 Compose)中重复使用内容信封。 你可以使用此函数表达式发送请求中带有 application/octet-stream 内容类型的字符串字节。

    返回操作在运行时的 body 输出。 actions('<actionName>').outputs.body 的速记。 See actions().

    body('<actionName>')
        "UserName": "ContosoInc",
        "FollowersCount": 172,
        "Description": "Leading the way in transforming the digital workplace.",
        "StatusesCount": 93,
        "FriendsCount": 126,
        "FavouritesCount": 46,
        "ProfileImageUrl": "https://pbs.twimg.com/profile_images/908820389907722240/gG9zaHcd_400x400.jpg"
    

    返回值的布尔版本。

    bool(<value>)
    
    chunk(createArray(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), 5)
    

    并返回以下结果:[ [1,2,3,4,5], [6,7,8,9,10], [11,12] ]

    返回一个或多个参数中的第一个非 null 值。 空字符串、空数组和空对象不为 NULL。

    coalesce(<object_1>, <object_2>, ...)
    

    这些示例返回指定值中的第一个非 null 值,当所有值均为 null 时返回 null:

    coalesce(null, true, false)
    coalesce(null, 'hello', 'world')
    coalesce(null, null, null)
    

    并返回以下结果:

  • 第一个示例:true
  • 第二个示例:"hello"
  • 第三个示例:null
  • concat

    组合两个或更多字符串,并返回组合后的字符串。

    concat('<text1>', '<text2>', ...)
    

    Azure 逻辑应用会自动或隐式执行 base64 编码和解码,因此,当你对需要编码或解码的数据使用 concat() 函数时,无需手动执行这些转换:

  • concat('data:;base64,',<value>)
  • concat('data:,',encodeUriComponent(<value>))
  • 但是,如果你仍然在设计器中使用此函数,则可能会在设计器中遇到意外的呈现行为。 这些行为仅影响函数的可见性,而不影响效果,除非你编辑函数的参数值,这样就会从代码中删除函数及其效果。 有关详细信息,请参阅 Base64 编码和解码

    Example

    此示例将字符串“Hello”和“World”组合到一起:

    concat('Hello', 'World')
    

    并返回以下结果:"HelloWorld"

    contains

    检查集合是否包含某个特定项。 当找到该项目时返回 true,找不到该项目时返回 false。 此函数区分大小写。

    contains('<collection>', '<value>')
    contains([<collection>], '<value>')
    

    具体而言,此函数对以下集合类型起作用:

  • A string to find a substring
  • An array to find a value
  • A dictionary to find a key
  • Example 2

    此示例检查字符串“hello world”中是否有子字符串“universe”并返回 false:

    contains('hello world', 'universe')
    

    convertFromUtc

    将时间戳从协调世界时 (UTC) 转换为目标时区。

    convertFromUtc('<timestamp>', '<destinationTimeZone>', '<format>'?)
                  Example 1

    此示例将时间戳转换为指定的时区:

    convertFromUtc('2018-01-01T08:00:00.0000000Z', 'Pacific Standard Time')
    

    并返回以下结果:"2018-01-01T00:00:00.0000000"

    Example 2

    此示例将时间戳转换为指定的时区和格式:

    convertFromUtc('2018-01-01T08:00:00.0000000Z', 'Pacific Standard Time', 'D')
    

    并返回以下结果:"Monday, January 1, 2018"

    convertTimeZone

    将时间戳从源时区转换为目标时区。

    convertTimeZone('<timestamp>', '<sourceTimeZone>', '<destinationTimeZone>', '<format>'?)
                  Example 1

    此示例将源时区转换为目标时区:

    convertTimeZone('2018-01-01T08:00:00.0000000Z', 'UTC', 'Pacific Standard Time')
    

    并返回以下结果:"2018-01-01T00:00:00.0000000"

    Example 2

    此示例将时区转换为指定的时区和格式:

    convertTimeZone('2018-01-01T80:00:00.0000000Z', 'UTC', 'Pacific Standard Time', 'D')
    

    并返回以下结果:"Monday, January 1, 2018"

    convertToUtc

    将时间戳从源时区转换为协调世界时 (UTC)。

    convertToUtc('<timestamp>', '<sourceTimeZone>', '<format>'?)
    
    convertToUtc('01/01/2018 00:00:00', 'Pacific Standard Time')
    

    并返回以下结果:"2018-01-01T08:00:00.0000000Z"

    Example 2

    此示例将时间戳转换为 UTC:

    convertToUtc('01/01/2018 00:00:00', 'Pacific Standard Time', 'D')
    

    并返回以下结果:"Monday, January 1, 2018"

    createArray

    从多个输入返回数组。 For single input arrays, see array().

    createArray('<object1>', '<object2>', ...)
    

    返回数据统一资源标识符 (URI) 的二进制版本。 Use this function rather than decodeDataUri(). 虽然这两个函数的工作方式相同,但首选 dataUriBinary()

    dataUriToBinary('<value>')
                  Example

    此示例创建以下数据 URI 的二进制版本:

    dataUriToBinary('data:text/plain;charset=utf-8;base64,aGVsbG8=')
    

    并返回以下结果:

    "01100100011000010111010001100001001110100111010001100101011110000111010000101111011100000 1101100011000010110100101101110001110110110001101101000011000010111001001110011011001010111 0100001111010111010101110100011001100010110100111000001110110110001001100001011100110110010 10011011000110100001011000110000101000111010101100111001101100010010001110011100000111101"

    dataUriToString

    返回数据统一资源标识符 (URI) 的字符串版本。

    dataUriToString('<value>')
                  Example

    此示例创建以下数据 URI 的字符串:

    dataUriToString('data:text/plain;charset=utf-8;base64,aGVsbG8=')
    

    并返回以下结果:"hello"

    dateDifference

    以时间跨度形式返回两个时间戳之间的差值。 此函数从 startDate 中减去 endDate,并以字符串格式返回时间戳结果。

    dateDifference('<startDate>', '<endDate>')
    

    将字符串中的小数数作为小数数返回。 当你处理需要小数精度的数据时,也可以使用此函数作为逻辑比较函数数学函数的输入。 To capture and preserve precision when you use the result from the decimal() function, wrap any decimal output with the string function. 下面的示例显示了这种用法,如果将小数结果用作数字,可能会丢失精度。

    在这个函数和 Azure Logic应用运行时的上下文中讨论的小数精度与 .NET 小数精度相同。

    decimal('<value>')
                  Example 2

    此示例创建一个小数,然后将结果转换为字符串以保持精度:

    string(decimal('1.2345678912312131')) // Returns "1.2345678912312131".
                  Example 3

    此示例对两个小数数字使用数学函数,并将结果用作数字:

    add(decimal('1.2345678912312131'), decimal('1.2345678912312131')) // Returns 2.469135782462426.
                  Example 4

    此示例对两个小数数字使用数学函数,并将结果转换为字符串以保持精度:

    string(add(decimal('1.2345678912312131'), decimal('1.2345678912312131'))) // Returns "2.4691357824624262".
    

    decodeBase64 (deprecated)

    This function is deprecated, so use base64ToString() instead.

    decodeDataUri

    返回数据统一资源标识符 (URI) 的二进制版本。 Consider using dataUriToBinary(), rather than decodeDataUri(). 虽然这两个函数的工作方式相同,但首选 dataUriToBinary()

    Azure 逻辑应用会自动或隐式执行 base64 编码和解码,因此你无需使用编码和解码函数手动执行这些转换。 但是,如果你仍然在设计器中使用这些函数,则可能会在设计器中遇到意外的呈现行为。 这些行为仅影响函数的可见性,而不影响其效果,除非你编辑函数的参数值,这样会从代码中删除函数及其效果。 有关详细信息,请参阅 Base64 编码和解码

    decodeDataUri('<value>')
                  Example

    此示例返回以下数据 URI 的二进制版本:

    decodeDataUri('data:text/plain;charset=utf-8;base64,aGVsbG8=')
    

    并返回以下结果:"hello"

    decodeUriComponent

    返回一个字符串,并将其中的转义字符替换为解码后的版本。

    decodeUriComponent('<value>')
    

    encodeUriComponent

    通过将 URL 不安全字符替换为转义字符来返回字符串的统一资源标识符 (URI) 编码版本。 Consider using uriComponent(), rather than encodeUriComponent(). 虽然这两个函数的工作方式相同,但首选 uriComponent()

    Azure 逻辑应用会自动或隐式执行 base64 编码和解码,因此你无需使用编码和解码函数手动执行这些转换。 但是,如果你仍然在设计器中使用这些函数,则可能会在设计器中遇到意外的呈现行为。 这些行为仅影响函数的可见性,而不影响其效果,除非你编辑函数的参数值,这样会从代码中删除函数及其效果。 有关详细信息,请参阅 Base64 编码和解码

    encodeUriComponent('<value>')
    

    float

    将浮点数的字符串版本转换为实际的浮点数。 仅当将自定义参数传递给应用(例如,逻辑应用工作流或 Power Automate 流)时,才使用此函数。 若要转换以区域设置特定格式表示的浮点字符串,可以选择指定 RFC 4646 区域设置代码。

    float('<value>', '<locale>'?)
                  Examples

    formatDateTime('03/15/2018') // Returns '2018-03-15T00:00:00.0000000'.
    formatDateTime('03/15/2018 12:00:00', 'yyyy-MM-ddTHH:mm:ss') // Returns '2018-03-15T12:00:00'.
    formatDateTime('01/31/2016', 'dddd MMMM d') // Returns 'Sunday January 31'.
    formatDateTime('01/31/2016', 'dddd MMMM d', 'fr-fr') // Returns 'dimanche janvier 31'.
    formatDateTime('01/31/2016', 'dddd MMMM d', 'fr-FR') // Returns 'dimanche janvier 31'.
    formatDateTime('01/31/2016', 'dddd MMMM d', 'es-es') // Returns 'domingo enero 31'.
    

    formDataMultiValues

    Return an array with values that match a key name in an action's form-data or form-encoded output.

    formDataMultiValues('<actionName>', '<key>')
                  Example

    此示例基于指定操作的表单数据或表单编码输出中的“Subject”键的值创建数组。

    formDataMultiValues('Send_an_email', 'Subject')
    

    并在数组中返回主题文本,例如:["Hello world"]

    formDataValue

    Return a single value that matches a key name in an action's form-data or form-encoded output. 如果此函数找到多个匹配项,此函数将引发错误。

    formDataValue('<actionName>', '<key>')
                  Example

    此示例基于指定操作的表单数据或表单编码输出中的“Subject”键的值创建字符串。

    formDataValue('Send_an_email', 'Subject')
    

    并以字符串形式返回主题文本,例如:"Hello world"

    formatNumber

    根据指定的格式以字符串形式返回一个数字。

    formatNumber(<number>, <format>, <locale>?)
                  Example 1

    假设你要设置数字 1234567890 的格式。 此示例将该数字的格式设置为字符串“1,234,567,890.00”。

    formatNumber(1234567890, '0,0.00', 'en-us')
    

    *Example 2"

    假设你要设置数字 1234567890 的格式。 此示例将该数字的格式设置为字符串“1.234.567.890,00”。

    formatNumber(1234567890, '0,0.00', 'is-is')
                  Example 3

    假设你要设置数字 17.35 的格式。 此示例将该数字的格式设置为字符串“$17.35”。

    formatNumber(17.35, 'C2')
                  Example 4

    假设你要设置数字 17.35 的格式。 此示例将该数字的格式设置为字符串“17,35 kr”。

    formatNumber(17.35, 'C2', 'is-is')
    

    getFutureTime

    返回当前时间戳加上指定的时间单位。

    getFutureTime(<interval>, <timeUnit>, <format>?)
    

    假设当前时间戳是“2018-03-01T00:00:00.0000000Z”。 此示例加上 5 天,并将结果转换为“D”格式:

    getFutureTime(5, 'Day', 'D')
    

    并返回以下结果:"Tuesday, March 6, 2018"

    getPastTime

    返回当前时间戳减去指定的时间单位。

    getPastTime(<interval>, <timeUnit>, <format>?)
    

    检查第一个值是否大于或等于第二个值。 当第一个值大于或等于第二个值时返回 true,当第一个值小于第二个值时返回 false。

    greaterOrEquals(<value>, <compareTo>)
    greaterOrEquals('<value>', '<compareTo>')
    

    isFloat

    返回一个布尔值,该值指示字符串是否为浮点数。 默认情况下,此函数使用浮点格式的固定区域性。 若要标识以其他区域设置特定格式表示的浮点数,可以选择指定 RFC 4646 区域设置代码。

    isFloat('<string>', '<locale>'?)
                  Example

    此示例创建一个计数器变量,在 Until 循环中每迭代一次该变量就会递增 1,直至计数器值达到 5。 此示例还创建一个变量,用于跟踪每次迭代的当前索引。 在 Until 循环的每次迭代时,此示例会递增计数器值,然后将该值指定给当前索引值,然后再递增计数器值。 在此循环中,此示例使用 iterationIndexes 函数引用当前迭代索引:

    iterationIndexes('Until_Max_Increment')

    "actions": { "Create_counter_variable": { "type": "InitializeVariable", "inputs": { "variables": [ "name": "myCounter", "type": "Integer", "value": 0 "runAfter": {} "Create_current_index_variable": { "type": "InitializeVariable", "inputs": { "variables": [ "name": "myCurrentLoopIndex", "type": "Integer", "value": 0 "runAfter": { "Create_counter_variable": [ "Succeeded" ] "Until_Max_Increment": { "type": "Until", "actions": { "Assign_current_index_to_counter": { "type": "SetVariable", "inputs": { "name": "myCurrentLoopIndex", "value": "@variables('myCounter')" "runAfter": { "Increment_variable": [ "Succeeded" ] "Compose": { "inputs": "'Current index: ' @{iterationIndexes('Until_Max_Increment')}", "runAfter": { "Assign_current_index_to_counter": [ "Succeeded" "type": "Compose" "Increment_variable": { "type": "IncrementVariable", "inputs": { "name": "myCounter", "value": 1 "runAfter": {} "expression": "@equals(variables('myCounter'), 5)", "limit": { "count": 60, "timeout": "PT1H" "runAfter": { "Create_current_index_variable": [ "Succeeded" ]

    返回字符串或 XML 的 JavaScript 对象表示法 (JSON) 类型值、对象或对象数组。

    json('<value>')
    json(xml('value'))
    

    Important

    如果不提供一个用于定义输出结构的 XML 架构,该函数可能会返回其结构与预期格式大不相同的结果,具体取决于输入。

    这种行为使得此函数不适合用于输出必须符合妥善定义的协定的情况,例如,在业务关键型系统或解决方案中。

    Example 3

    此示例使用 json()xml() 函数将根元素中具有单个子元素的 XML 转换为该子元素的名为 person 的 JSON 对象:

    json(xml('<?xml version="1.0"?> <root> <person id="1"> <name>Sophia Owen</name> <occupation>Engineer</occupation> </person> </root>'))

    并返回以下结果:

    "?xml": { "@version": "1.0" "root": { "person": { "@id": "1", "name": "Sophia Owen", "occupation": "Engineer" Example 4

    此示例使用 json()xml() 函数将根元素中具有多个子元素的 XML 转换为一个数组,其中包含这些子元素的名为 person 的 JSON 对象:

    json(xml('<?xml version="1.0"?> <root> <person id="1"> <name>Sophia Owen</name> <occupation>Engineer</occupation> </person> <person id="2"> <name>John Doe</name> <occupation>Engineer</occupation> </person> </root>'))

    并返回以下结果:

    "?xml": { "@version": "1.0" "root": { "person": [ "@id": "1", "name": "Sophia Owen", "occupation": "Engineer" "@id": "2", "name": "John Doe", "occupation": "Engineer"

    intersection

    Return a collection that has only the common items across the specified collections. 某个项必须出现在传递给此函数的所有集合中才会出现在结果中。 如果一个或多个项具有相同的名称,则具有该名称的最后一项将出现在结果中。

    intersection([<collection1>], [<collection2>], ...)
    intersection('<collection1>', '<collection2>', ...)
                  Example

    此示例查找以下数组中的共有项:

    intersection(createArray(1, 2, 3), createArray(101, 2, 1, 10), createArray(6, 8, 1, 2))
    

    And returns an array with only these items: [1, 2]

    Return a string that has all the items from an array and has each character separated by a delimiter.

    join([<collection>], '<delimiter>')
                  Examples

    此示例查找 world 字符串中最后一次出现的 hello world hello world 子字符串的起始索引值。 返回的结果为 18

    lastIndexOf('hello world hello world', 'world')
    

    此示例缺少子字符串参数,将返回 22 值,因为输入字符串 (23) 减 1 后的值大于 0。

    lastIndexOf('hello world hello world', '')
    

    length

    返回集合中的项数。

    length('<collection>')
    length([<collection>])
    

    检查第一个值是否小于或等于第二个值。 当第一个值小于或等于第二个值时返回 true,当第一个值大时返回 false。

    lessOrEquals(<value>, <compareTo>)
    lessOrEquals('<value>', '<compareTo>')
    

    listCallbackUrl

    返回调用某个触发器或操作的“回调 URL”。 This function works only with triggers and actions for the HttpWebhook and ApiConnectionWebhook connector types, but not the Manual, Recurrence, HTTP, and APIConnection types.

    listCallbackUrl()
                  Example

    此示例显示了此函数可能会返回的示例回调 URL:

    "https://prod-01.westus.logic.azure.com:443/workflows/<*workflow-ID*>/triggers/manual/run?api-version=2016-10-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=<*signature-ID*>"

    返回列表中或包括两端数字在内的数组中的最大值。

    max(<number1>, <number2>, ...)
    max([<number1>, <number2>, ...])
    

    nthIndexOf

    Return the starting position or index value where the nth occurrence of a substring appears in a string.

    nthIndexOf('<text>', '<searchText>', <occurrence>)
                  Examples

    nthIndexOf('123456789123465789', '1', 1) // Returns `0`.
    nthIndexOf('123456789123465789', '1', 2) // Returns `9`.
    nthIndexOf('123456789123465789', '12', 2) // Returns `9`.
    nthIndexOf('123456789123465789', '6', 4) // Returns `-1`.
    

    检查是否至少一个表达式为真。 当至少一个表达式为 true 时返回 true,当所有表达式均为 false 时返回 false。

    or(<expression1>, <expression2>, ...)
        "Pragma": "no-cache",
        "Vary": "Accept-Encoding",
        "x-ms-request-id": "a916ec8f52211265d98159adde2efe0b",
        "X-Content-Type-Options": "nosniff",
        "Timing-Allow-Origin": "*",
        "Cache-Control": "no-cache",
        "Date": "Mon, 09 Apr 2018 18:47:12 GMT",
        "Set-Cookie": "ARRAffinity=b9400932367ab5e3b6802e3d6158afffb12fcde8666715f5a5fbd4142d0f0b7d;Path=/;HttpOnly;Domain=twitter-wus.azconn-wus.p.azurewebsites.net",
        "X-AspNet-Version": "4.0.30319",
        "X-Powered-By": "ASP.NET",
        "Content-Type": "application/json; charset=utf-8",
        "Expires": "-1",
        "Content-Length": "339"
      "body": {
        "FullName": "Contoso Corporation",
        "Location": "Generic Town, USA",
        "Id": 283541717,
        "UserName": "ContosoInc",
        "FollowersCount": 172,
        "Description": "Leading the way in transforming the digital workplace.",
        "StatusesCount": 93,
        "FriendsCount": 126,
        "FavouritesCount": 46,
        "ProfileImageUrl": "https://pbs.twimg.com/profile_images/908820389907722240/gG9zaHcd_400x400.jpg"
    

    parameters

    返回工作流定义中描述的参数的值。

    parameters('<parameterName>')
                  Examples

    parseDateTime('20/10/2014', 'fr-fr') // Returns '2014-10-20T00:00:00.0000000'.
    parseDateTime('20 octobre 2010', 'fr-FR') // Returns '2010-10-20T00:00:00.0000000'.
    parseDateTime('martes 20 octubre 2020', 'es-es') // Returns '2020-10-20T00:00:00.0000000'.
    parseDateTime('21052019', 'fr-fr', 'ddMMyyyy') // Returns '2019-05-21T00:00:00.0000000'.
    parseDateTime('20190521', 'fr-fr', 'yyyyMMdd') // Returns '2019-05-21T00:00:00.0000000'.
    parseDateTime('10/20/2014 15h', 'en-US', 'MM/dd/yyyy HH\h') // Returns '2014-10-20T15:00:00.0000000'.
    

    返回指定范围(仅包括起端在内)中的一个随机整数。

    rand(<minValue>, <maxValue>)
                  Example 1

    This example removes the middleName property from a JSON object, which is converted from a string to JSON by using the JSON() function, and returns the updated object:

    removeProperty(json('{ "firstName": "Sophia", "middleName": "Anne", "surName": "Owen" }'), 'middleName')
    

    下面是当前的 JSON 对象:

    "firstName": "Sophia", "middleName": "Anne", "surName": "Owen"

    下面是已更新的 JSON 对象:

    "firstName": "Sophia", "surName": "Owen" Example 2

    This example removes the middleName child property from a customerName parent property in a JSON object, which is converted from a string to JSON by using the JSON() function, and returns the updated object:

    removeProperty(json('{ "customerName": { "firstName": "Sophia", "middleName": "Anne", "surName": "Owen" } }')['customerName'], 'middleName')
    

    下面是当前的 JSON 对象:

    "customerName": { "firstName": "Sophia", "middleName": "Anne", "surName": "Owen"

    下面是已更新的 JSON 对象:

    "customerName": { "firstName": "Sophia", "surName": "Owen"

    将子字符串替换为指定字符串,并返回结果字符串。 此函数区分大小写。

    replace('<text>', '<oldText>', '<newText>')
                  Example

    此示例查找“the old string”中的“old”子字符串并将“old”替换为“new”:

    replace('the old string', 'old', 'new')
    

    并返回以下结果:"the new string"

    result

    返回指定的有范围操作(例如 For_eachUntilScope 操作)中顶级操作的结果。 result() 函数接受单个参数(范围的名称),并返回一个数组,其中包含该范围内的顶级操作中的信息。 这些操作对象包含的特性(例如操作的开始时间、结束时间、状态、输入、相关 ID 和输出)与 actions() 函数返回的特性相同。

    This function returns information only from the first-level actions in the scoped action and not from deeper nested actions such as switch or condition actions.

    例如,可以使用此函数获取失败操作的结果,以便可以诊断和处理异常。 有关详细信息,请参阅获取失败的上下文和结果

    result('<scopedActionName>')
                       "X-AspNetMvc-Version": "5.1",
                       "Access-Control-Allow-Origin": "*",
                       "Cache-Control": "private",
                       "Date": "Tue, 20 Aug 2019 22:15:37 GMT",
                       "Set-Cookie": "ARRAffinity=0285cfbea9f2ee7",
                       "Server": "Microsoft-IIS/10.0",
                       "X-AspNet-Version": "4.0.30319",
                       "X-Powered-By": "ASP.NET",
                       "Content-Length": "0"
                   "startTime": "2019-08-20T22:15:37.6919631Z",
                   "endTime": "2019-08-20T22:15:37.95762Z",
                   "trackingId": "6bad3015-0444-4ccd-a971-cbb0c99a7.....",
                   "clientTrackingId": "085863526764.....",
                   "code": "OK",
                   "status": "Succeeded"
                "name": "HTTP",
                "inputs": {
                   "uri": "https://httpstat.us/200",
                   "method": "GET"
                "outputs": {
                "statusCode": 200,
                   "headers": {
                       "X-AspNetMvc-Version": "5.1",
                       "Access-Control-Allow-Origin": "*",
                       "Cache-Control": "private",
                       "Date": "Tue, 20 Aug 2019 22:15:37 GMT",
                       "Set-Cookie": "ARRAffinity=0285cfbea9f2ee7",
                       "Server": "Microsoft-IIS/10.0",
                       "X-AspNet-Version": "4.0.30319",
                       "X-Powered-By": "ASP.NET",
                       "Content-Length": "0"
                   "startTime": "2019-08-20T22:15:37.6919631Z",
                   "endTime": "2019-08-20T22:15:37.95762Z",
                   "trackingId": "9987e889-981b-41c5-aa27-f3e0e59bf69.....",
                   "clientTrackingId": "085863526764.....",
                   "code": "OK",
                   "status": "Succeeded"
    

    reverse

    反转集合中项的顺序。 When you use this function with sort(), you can sort a collection in descending order.

    reverse([<collection>])
    

    setProperty

    设置 JSON 对象的属性值并返回更新的对象。 如果尝试设置的属性不存在,则会为对象添加该属性。 To add a new property, use the addProperty() function.

    setProperty(<object>, '<property>', <value>)
                  Example 1

    This example sets the surName property in a JSON object, which is converted from a string to JSON by using the JSON() function. 该函数将指定的值分配给属性,并返回更新后的对象:

    setProperty(json('{ "firstName": "Sophia", "surName": "Owen" }'), 'surName', 'Hartnett')
    

    下面是当前的 JSON 对象:

    "firstName": "Sophia", "surName": "Owen"

    下面是已更新的 JSON 对象:

    "firstName": "Sophia", "surName": "Hartnett" Example 2

    This example sets the surName child property for the customerName parent property in a JSON object, which is converted from a string to JSON by using the JSON() function. 该函数将指定的值分配给属性,并返回更新后的对象:

    setProperty(json('{ "customerName": { "firstName": "Sophia", "surName": "Owen" } }'), 'customerName', setProperty(json('{ "customerName": { "firstName": "Sophia", "surName": "Owen" } }')['customerName'], 'surName', 'Hartnett'))
    

    下面是当前的 JSON 对象:

    "customerName": { "firstName": "Sophie", "surName": "Owen"

    下面是已更新的 JSON 对象:

    "customerName": { "firstName": "Sophie", "surName": "Hartnett"

    将集合开头的项删除,并返回其余所有项目。

    skip([<collection>], <count>)
                  Examples

    slice('Hello World', 2) // Returns 'llo World'.
    slice('Hello World', 30) // Returns ''.
    slice('Hello World', 10, 2) // Returns ''.
    slice('Hello World', 0) // Returns 'Hello World'.
    slice('Hello World', 2, 5) // Returns 'llo'.
    slice('Hello World', 6, 20) // Returns 'World'.
    slice('Hello World', -2) // Returns 'ld'.
    slice('Hello World', 3, -1) // Returns 'lo Worl'.
    slice('Hello World', 3, 3) // Returns ''.
    

    对集合中的项进行排序。 可以使用包含简单类型的任何键对集合对象进行排序。

    sort([<collection>], <sortBy>?)
                  Example 2

    此示例按键对对象数组进行排序:

    sort(createArray(json('{ "first": "Amalie", "last": "Rose" }'), json('{ "first": "Elise", "last": "Renee" }')), 'last')
    

    并返回此数组:[{ "first": "Elise", "last": "Renee" }, {"first": "Amalie", "last": "Rose" }')]

    根据原始字符串中指定的分隔符字符,返回一个包含子字符串(以逗号分隔)的数组。

    split('<text>', '<delimiter>')
                  Example 2

    此示例检查“hello world”字符串是否以“greetings”子字符串开头:

    startsWith('hello world', 'greetings')
    

    并返回以下结果:false

    返回值的字符串版本。

    string(<value>)
                  Example 2

    此示例为指定的 JSON 对象创建字符串并使用反斜杠字符 (\) 作为双引号 (") 的转义字符。

    string( { "name": "Sophie Owen" } )
    

    并返回以下结果:"{ \\"name\\": \\"Sophie Owen\\" }"

    返回第一个数字减去第二个数字得到的结果。

    sub(<minuend>, <subtrahend>)
    

    Make sure that the sum from adding the startIndex and length parameter values is less than the length of the string that you provide for the text parameter. Otherwise, you get an error, unlike similar functions in other languages where the result is the substring from the startIndex to the end of the string. The length parameter is optional and if not provided, the substring() function takes all the characters beginning from startIndex to the end of the string.

    subtractFromTime('2018-01-02T00:00:00Z', 1, 'Day')
    

    并返回以下结果:"2018-01-01T00:00:00.0000000Z"

    Example 2

    此示例从以下时间戳中减去 1 天:

    subtractFromTime('2018-01-02T00:00:00Z', 1, 'Day', 'D')
    

    并使用可选的“D”格式返回以下结果:"Monday, January, 1, 2018"

    返回集合开头的项。

    take('<collection>', <count>)
    take([<collection>], <count>)
    

    ticks

    返回自 0001 年 1 月 1 日午夜 12:00:00(或 C# 中的 DateTime.Ticks)到指定时间戳的间隔为 100 毫微秒的时钟周期数。 有关详细信息,请参阅此主题:DateTime.Ticks 属性(系统)

    ticks('<timestamp>')
    

    默认情况下,此函数引用整个触发器对象,但是也可以指定你需要其值的属性。 Also, this function has shorthand versions available, see triggerOutputs() and triggerBody().

    trigger()
    

    triggerFormDataMultiValues

    Return an array with values that match a key name in a trigger's form-data or form-encoded output.

    triggerFormDataMultiValues('<key>')
    
    triggerFormDataMultiValues('feedUrl')
    

    并将以下数组返回为示例结果:["https://feeds.a.dj.com/rss/RSSMarketsMain.xml"]

    triggerFormDataValue

    Return a string with a single value that matches a key name in a trigger's form-data or form-encoded output. 如果此函数找到多个匹配项,此函数将引发错误。

    triggerFormDataValue('<key>')
    
    triggerFormDataValue('feedUrl')
    

    并将以下字符串返回为示例结果:"https://feeds.a.dj.com/rss/RSSMarketsMain.xml"

    triggerMultipartBody

    返回具有多个部分的触发器输出中某个特定部分的正文。

    triggerMultipartBody(<index>)
    

    Return a collection that has all the items from the specified collections. 某个项只要出现在传递给此函数的任一集合中便会出现在结果中。 如果一个或多个项具有相同的名称,则具有该名称的最后一项将出现在结果中。

    union('<collection1>', '<collection2>', ...)
    union([<collection1>], [<collection2>], ...)
                  Example

    This example gets all the items from these collections:

    union(createArray(1, 2, 3), createArray(1, 2, 10, 101))
    

    并返回以下结果:[1, 2, 3, 10, 101]

    uriComponent

    通过将 URL 不安全字符替换为转义字符来返回字符串的统一资源标识符 (URI) 编码版本。 Use this function rather than encodeUriComponent(). 虽然这两个函数的工作方式相同,但首选 uriComponent()

    uriComponent('<value>')
                  Example

    此示例查找以下 URI 的 path 值:

    uriPath('https://www.contoso.com/catalog/shownew.htm?date=today')
    

    并返回以下结果:"/catalog/shownew.htm"

    uriPathAndQuery

    返回统一资源标识符 (URI) 的 pathquery 值。

    uriPathAndQuery('<uri>')
                  Example

    此示例查找以下 URI 的 pathquery 值:

    uriPathAndQuery('https://www.contoso.com/catalog/shownew.htm?date=today')
    

    并返回以下结果:"/catalog/shownew.htm?date=today"

    uriPort

    返回统一资源标识符 (URI) 的 port 值。

    uriPort('<uri>')
                  Example

    此示例查找以下 URI 的 query 值:

    uriQuery('https://www.contoso.com/catalog/shownew.htm?date=today')
    

    并返回以下结果:"?date=today"

    uriScheme

    返回统一资源标识符 (URI) 的 scheme 值。

    uriScheme('<uri>')
                  Example

    此示例查找以下 URI 的 scheme 值:

    uriScheme('https://www.contoso.com/catalog/shownew.htm?date=today')
    

    并返回以下结果:"http"

    utcNow

    返回当前时间戳。

    utcNow('<format>')
    

    Optionally, you can specify a different format with the <format> parameter.

    Parameter Required Description String 需要获取其值的工作流属性的名称



    默认情况下,工作流对象具有以下属性:nametypeidlocationruntags



    - run 属性值是包含以下属性的 JSON 对象:nametypeid



    - tags 属性是一个 JSON 对象,其中包含与 Azure 逻辑应用中的逻辑应用或者 Power Automate 中的流关联的标记,以及这些标记的值。 有关 Azure 资源中的标记的详细信息,请查看在 Azure 中标记资源、资源组和订阅以对其进行逻辑有序的组织



    Note: By default, a logic app has no tags, but a Power Automate flow has the flowDisplayName and environmentName tags. Example 2

    如果使用 Power Automate,可以创建一个使用 @workflow() 输出属性从流的 tagsflowDisplayName 属性获取值的 environmentName 表达式。

    例如,可以从流本身发送链接回到你的流的自定义电子邮件通知。 这些通知可以包含一个 HTML 链接,其中包含流在电子邮件标题中的显示名称。该链接遵循以下语法:

    <a href=https://flow.microsoft.com/manage/environments/@{workflow()['tags']['environmentName']}/flows/@{workflow()['name']}/details>Open flow @{workflow()['tags']['flowDisplayName']}</a>

    返回包含 JSON 对象的字符串的 XML 版本。

    xml('<value>')
    

    此示例创建包含以下 JSON 对象的字符串的 XML:

    xml(json('{"person": {"name": "Sophia Owen", "city": "Seattle"}}'))

    并返回以下结果 XML:

    <person>
      <name>Sophia Owen</name>
      <city>Seattle</city>
    <person>
    

    xpath

    检查 XML 中是否存在与 XPath(XML 路径语言)表达式匹配的节点或值,并返回匹配的节点或值。 XPath 表达式或单纯的“XPath”有助于在 XML 文档结构中导航,以便可以在 XML 内容中选择节点或计算值。

    在消耗和标准逻辑应用中,所有函数表达式都使用 .NET XPath 库。 XPath 表达式与基础 .NET 库兼容,并且仅支持基础 .NET 库支持的表达式。

    xpath('<xml>', '<xpath>')
    </produce>
    

    此示例传入 XPath 表达式 '/produce/item/name/text()',以查找与 <name></name> XML 字符串中的 'items' 节点匹配的节点,并返回包含这些节点值的数组:

    xpath(xml(parameters('items')), '/produce/item/name/text()')

    The example also uses the parameters() function to get the XML string from 'items' and convert the string to XML format by using the xml() function.

    以下结果数组填充了与 <name></name> 匹配的节点的值:

    [ Gala, Honeycrisp ]

    Example 2

    此示例是示例 1 的延续,它传入 XPath 表达式 '/produce/item/name[1]' 来查找作为 name 元素的子级的第一个 item 元素。

    xpath(xml(parameters('items')), '/produce/item/name[1]')

    结果如下:Gala

    Example 3

    此示例是示例 1 的延续,它传入 XPath 表达式 '/produce/item/name[last()]' 来查找作为 name 元素的子级的最后一个 item 元素。

    xpath(xml(parameters('items')), '/produce/item/name[last()]')

    结果如下:Honeycrisp

    Example 4

    此示例假设 items XML 字符串还包含特性 expired='true'expired='false'

    <?xml version="1.0"?>
    <produce>
        <name expired='true'>Gala</name>
        <type>apple</type>
        <count>20</count>
      </item>
        <name expired='false'>Honeycrisp</name>
        <type>apple</type>
        <count>10</count>
      </item>
    </produce>
    

    此示例传入 XPath 表达式 '//name[@expired]' 来查找具有 name 特性的所有 expired 元素:

    xpath(xml(parameters('items')), '//name[@expired]')

    结果如下:[ Gala, Honeycrisp ]

    Example 5

    此示例假设 items XML 字符串只包含特性 expired = 'true'

    <?xml version="1.0"?>
    <produce>
        <name expired='true'>Gala</name>
        <type>apple</type>
        <count>20</count>
      </item>
        <name>Honeycrisp</name>
        <type>apple</type>
        <count>10</count>
      </item>
    </produce>
    

    此示例传入 XPath 表达式 '//name[@expired = 'true']' 来查找具有 name 特性的所有 expired = 'true' 元素:

    xpath(xml(parameters('items')), '//name[@expired = 'true']')

    结果如下:[ Gala ]

    Example 6

    此示例假设 items XML 字符串还包含以下特性:

  • expired='true' price='12'
  • expired='false' price='40'
  • <?xml version="1.0"?>
    <produce>
        <name expired='true' price='12'>Gala</name>
        <type>apple</type>
        <count>20</count>
      </item>
        <name expired='false' price='40'>Honeycrisp</name>
        <type>apple</type>
        <count>10</count>
      </item>
    </produce>
    

    此示例传入 XPath 表达式 '//name[@price>35]' 来查找具有 name 的所有 price > 35 元素:

    xpath(xml(parameters('items')), '//name[@price>35]')

    结果如下:Honeycrisp

    Example 7

    此示例假设 items XML 字符串与示例 1 中的字符串相同:

    <?xml version="1.0"?>
    <produce>
        <name>Gala</name>
        <type>apple</type>
        <count>20</count>
      </item>
        <name>Honeycrisp</name>
        <type>apple</type>
        <count>10</count>
      </item>
    </produce>
    

    此示例查找与 <count></count> 节点匹配的节点并通过 sum() 函数添加这些节点值:

    xpath(xml(parameters('items')), 'sum(/produce/item/count)')

    结果如下:30

    Example 8

    此示例假设你有以下 XML 字符串,其中包含 XML 文档命名空间 xmlns="https://contoso.com"

    <?xml version="1.0"?><file xmlns="https://contoso.com"><location>Paris</location></file>