首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LogicApp -如何检查集合是否为空

LogicApp -如何检查集合是否为空
EN

Stack Overflow用户
提问于 2022-07-11 20:43:54
回答 1查看 276关注 0票数 0

如果有addOn数组,我想要做的是将"xxx“这个词添加到名称的末尾。

代码语言:javascript
复制
Schema applied to message.
{
    "properties": {
        "appointment": {
            "properties": {
                "id": {
                    "type": "integer"
                },
                "lines": {
                    "items": {
                        "properties": {
                            "addOn": {
                                "items": {
                                    "properties": {
                                        "id": {
                                            "type": "integer"
                                        },
                                        "name": {
                                            "type": "string"
                                        }
                                    },
                                    "required": [
                                        "id",
                                        "name"
                                    ],
                                    "type": "object"
                                },
                                "type": "array"
                            },
                            "id": {
                                "type": "integer"
                            },
                            "price": {
                                "type": "integer"
                            }
                        },
                        "required": [
                            "id",
                            "price"
                        ],
                        "type": "object"
                    },
                    "type": "array"
                }
            },
            "type": "object"
        },
        "messageId": {
            "type": "string"
        }
    },
    "type": "object"
}

Message 1
{
  "messageId": "11",
  "appointment": {
    "id": 22,
     "lines": [
      {
        "id": 33,
        "price": 125.0,
        "addOn": [
          {
            "id": 44,
            "name": "test"
          }
        ]
      }
    ]
  }
}

Message 2
{
  "messageId": "11",
  "appointment": {
    "id": 22,
     "lines": [
      {
        "id": 33,
        "price": 125.0
      }
    ]
  }
}

Message 1工作正常,但是每当我尝试使用length或Parse时,我都会收到一条消息,表示addOn为null。

当没有addOn数组时,我如何才能将适当的条件表示为不获取任何错误或什么也不做。

逻辑应用程序

Message1 -好的

Message2 -误差

代码视图。{“定义”:{ "$schema":"https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",“actions:{ "For_each":{ "For_each_2":{ "actions":{ "actions":{},"Condition_3":{”Condition_3“:{ },”表达式“:{”等于“:”@For_each(项目‘For_each_2’)“,"True”},"runAfter":{},"type":"If“},"foreach":"@items('For_each')'addOn'","runAfter":{},"type":"Foreach”},"foreach":“@body(‘Parse_JSON’)?‘Parse_JSON’行‘”,"runAfter":{ "Parse_JSON":“成功”},“类型”:"Foreach“}"Parse_JSON":{“Parse_JSON”:{ "content":"@triggerBody()","schema":{ "properties":{ "id":{ "type":“整型”},“行”:{“项目”:{“属性”:{ "addOn":{“属性”:{ "id“:{”类型“:”整数“},”名称“:{”类型“:”字符串“},”必需“:”id“、”名称“、”类型“:”对象“}、”类型“:”数组“},"id“:{”类型“:”整型“}、”价格“:{”类型“:”整数“}、”必需“:”id“、”价格“、”类型“:”对象“}、”类型“:”数组“}、”类型“:”对象“}、"messageId":{”类型“:”字符串“}、”类型“:”类型“:”对象“}。"runAfter":{},“类型”:"ParseJson“},"contentVersion":"1.0.0.0",”输出“:{},”参数“:{},”触发器“:{”手动“:{”输入“:{”模式“:{”属性“:{”任命“:{”属性“:{ "id":{”类型“:”整数“},“行”:{“项目”:{“属性”:{ "addOn":{“属性”:{ "id“:{”类型“:”整数“},”名称“:{”类型“:”字符串“},”必需“:”id“、”名称“、”类型“:”对象“}、”类型“:”数组“},"id":{“类型”:“整型”},“价格”:{“类型”:“整数”},“必需”:"id",“价格”,"addOn“,”类型“:”对象“},”类型“:”数组“},”类型“:”对象“},"messageId":{”类型“:”字符串“},“类型”:“对象”},“种类”:"Http",“类型”:“请求”} },“参数”:{} }

史蒂夫

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-15 01:18:35

我想在名字的末尾加上"xxx“这个词。

对于追加,您可以在设置"name“变量时直接添加。

或者,您也可以使用concat函数,如下所示。

代码语言:javascript
复制
concat(body('Parse_JSON')?['appointment']?['lines'][0]['addOn'][0]['name'],variables('xxx'))

如果这两种情况都会给出如下结果

--当没有addOn数组时,我如何才能将适当的条件表示为不获取任何错误或什么也不做。

如果行中包含"addOn“或不包含”addOn“,则可以通过多种方式使用其中一种解决方案。

代码语言:javascript
复制
"contains": ["@body('Parse_JSON')?['appointment']?['lines'][0]","addOn"]

MESSAGE1结果:

MESSAGE2结果:

您可以使用下面的代码视图在您的逻辑应用程序中复制相同的内容。

代码语言:javascript
复制
{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Compose": {
                "inputs": "@variables('Message')",
                "runAfter": {
                    "For_each": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            },
            "For_each": {
                "actions": {
                    "Condition": {
                        "actions": {
                            "Set_variable": {
                                "inputs": {
                                    "name": "Message",
                                    "value": {
                                        "appointment": {
                                            "id": "@body('Parse_JSON')?['appointment']?['id']",
                                            "lines": [
                                                {
                                                    "addOn": "addOn is NULL",
                                                    "id": "@items('For_each')?['id']",
                                                    "price": "@items('For_each')?['price']"
                                                }
                                            ]
                                        },
                                        "messageId": "@{body('Parse_JSON')?['messageId']}"
                                    }
                                },
                                "runAfter": {},
                                "type": "SetVariable"
                            }
                        },
                        "else": {
                            "actions": {
                                "For_each_2": {
                                    "actions": {
                                        "Set_variable_2": {
                                            "inputs": {
                                                "name": "Message",
                                                "value": {
                                                    "appointment": {
                                                        "id": "@body('Parse_JSON')?['appointment']?['id']",
                                                        "lines": [
                                                            {
                                                                "addOn": [
                                                                    {
                                                                        "id": "@items('For_each_2')?['id']",
                                                                        "name": "@{concat(body('Parse_JSON')?['appointment']?['lines'][0]['addOn'][0]['name'],variables('xxx'))}"
                                                                    }
                                                                ],
                                                                "id": "@items('For_each')?['id']",
                                                                "price": "@items('For_each')?['price']"
                                                            }
                                                        ]
                                                    },
                                                    "messageId": "@{body('Parse_JSON')?['messageId']}"
                                                }
                                            },
                                            "runAfter": {},
                                            "type": "SetVariable"
                                        }
                                    },
                                    "foreach": "@items('For_each')['addOn']",
                                    "runAfter": {},
                                    "type": "Foreach"
                                }
                            }
                        },
                        "expression": {
                            "and": [
                                {
                                    "not": {
                                        "contains": [
                                            "@body('Parse_JSON')?['appointment']?['lines'][0]",
                                            "addOn"
                                        ]
                                    }
                                }
                            ]
                        },
                        "runAfter": {},
                        "type": "If"
                    }
                },
                "foreach": "@body('Parse_JSON')?['appointment']?['lines']",
                "runAfter": {
                    "Initialize_variable_xxx": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Initialize_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "Message",
                            "type": "object"
                        }
                    ]
                },
                "runAfter": {
                    "Parse_JSON": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Initialize_variable_xxx": {
                "inputs": {
                    "variables": [
                        {
                            "name": "xxx",
                            "type": "string",
                            "value": "xxx"
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Parse_JSON": {
                "inputs": {
                    "content": "@triggerBody()",
                    "schema": {
                        "properties": {
                            "appointment": {
                                "properties": {
                                    "id": {
                                        "type": "integer"
                                    },
                                    "lines": {
                                        "items": {
                                            "properties": {
                                                "addOn": {
                                                    "items": {
                                                        "properties": {
                                                            "id": {
                                                                "type": "integer"
                                                            },
                                                            "name": {
                                                                "type": "string"
                                                            }
                                                        },
                                                        "required": [
                                                            "id",
                                                            "name"
                                                        ],
                                                        "type": "object"
                                                    },
                                                    "type": "array"
                                                },
                                                "id": {
                                                    "type": "integer"
                                                },
                                                "price": {
                                                    "type": "integer"
                                                }
                                            },
                                            "required": [
                                                "id",
                                                "price"
                                            ],
                                            "type": "object"
                                        },
                                        "type": "array"
                                    }
                                },
                                "type": "object"
                            },
                            "messageId": {
                                "type": "string"
                            }
                        },
                        "type": "object"
                    }
                },
                "runAfter": {},
                "type": "ParseJson"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {
                        "properties": {
                            "appointment": {
                                "properties": {
                                    "id": {
                                        "type": "integer"
                                    },
                                    "lines": {
                                        "items": {
                                            "properties": {
                                                "addOn": {
                                                    "items": {
                                                        "properties": {
                                                            "id": {
                                                                "type": "integer"
                                                            },
                                                            "name": {
                                                                "type": "string"
                                                            }
                                                        },
                                                        "required": [
                                                            "id",
                                                            "name"
                                                        ],
                                                        "type": "object"
                                                    },
                                                    "type": "array"
                                                },
                                                "id": {
                                                    "type": "integer"
                                                },
                                                "price": {
                                                    "type": "integer"
                                                }
                                            },
                                            "required": [
                                                "id",
                                                "price",
                                                "addOn"
                                            ],
                                            "type": "object"
                                        },
                                        "type": "array"
                                    }
                                },
                                "type": "object"
                            },
                            "messageId": {
                                "type": "string"
                            }
                        },
                        "type": "object"
                    }
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {}
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72944461

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档