如何在Azure Logic App的``是否''条件操作中执行``空''检查 [英] How to do a 'null' check in 'if' condition action of Azure Logic App

查看:58
本文介绍了如何在Azure Logic App的``是否''条件操作中执行``空''检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个逻辑应用程序,其中包含一些触发器,一个"http"连接器以及一个"If"条件活动. "http"连接器返回"json"结果,例如jsonObj.

我可以将条件检查为@equal(body('HTTP')['jsonObj'].someProperty,'someValue'),但不能对该someProperty值进行null检查.

下面是我尝试过的一些方法,这些方法都行不通.

@equal(body('HTTP')['jsonObj'].someProperty, null) --Unable to save
@equal(body('HTTP')['jsonObj']?.someProperty,'null') --Comparing with string value 'null'

解决方案

我没有找到真正的方法来对直接测试但是,选择足够的随机"字符串时采取以下解决办法应该工作coalesce

的后备

...
"propExists": "@equals(coalesce(triggerBody()?.prop, 'Fallback42'), 'Fallback42')"
...

例如,以下逻辑应用将回显属性prop以及是否实际指定了该属性

{
    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
    "actions": {
        "Response": {
            "inputs": {
                "body": {
                    "propNull": "@equals(coalesce(triggerBody()?.prop, 'undefined'), 'undefined')",
                    "prop": "@triggerBody()?.prop"
                },
                "statusCode": 200
            },
            "runAfter": {},
            "type": "Response"
        }
    },
    "contentVersion": "1.0.0.0",
    "outputs": {},
    "parameters": {},
    "triggers": {
        "request": {
            "inputs": {
                "schema": {}
            },
            "kind": "Http",
            "type": "Request"
        }
    }
}

这样带有

的请求

{
    "prop": "test"
}

结果

{
  "prop": "test",
  "propNull": false
}

而带有

的请求

{
    "propOther": "test"
}

结果

{
  "prop": null,
  "propNull": true
}

I've created a logic app which contains some trigger, an 'http' connector and then an 'If' condition activity. The 'http' connector returns a 'json' result say jsonObj.

I'm able to check condition as @equal(body('HTTP')['jsonObj'].someProperty,'someValue') but not able to do a null check on that someProperty value.

Below are some ways I tried which are not working.

@equal(body('HTTP')['jsonObj'].someProperty, null) --Unable to save
@equal(body('HTTP')['jsonObj']?.someProperty,'null') --Comparing with string value 'null'

解决方案

I did not found a real way to directly test against null or undefined but the following workaround should work when choosing a sufficient 'random' string as fallback for the coalesce

...
"propExists": "@equals(coalesce(triggerBody()?.prop, 'Fallback42'), 'Fallback42')"
...

For example the following Logic App would echo back the property prop and whether it was actually specified or not

{
    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
    "actions": {
        "Response": {
            "inputs": {
                "body": {
                    "propNull": "@equals(coalesce(triggerBody()?.prop, 'undefined'), 'undefined')",
                    "prop": "@triggerBody()?.prop"
                },
                "statusCode": 200
            },
            "runAfter": {},
            "type": "Response"
        }
    },
    "contentVersion": "1.0.0.0",
    "outputs": {},
    "parameters": {},
    "triggers": {
        "request": {
            "inputs": {
                "schema": {}
            },
            "kind": "Http",
            "type": "Request"
        }
    }
}

so that a request with

{
    "prop": "test"
}

results in

{
  "prop": "test",
  "propNull": false
}

whereas a request with

{
    "propOther": "test"
}

results in

{
  "prop": null,
  "propNull": true
}

这篇关于如何在Azure Logic App的``是否''条件操作中执行``空''检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆