gpt4 book ai didi

json - 将 JSON 数组解析为 Azure 逻辑应用中的各个变量

转载 作者:行者123 更新时间:2023-12-03 03:28:21 26 4
gpt4 key购买 nike

我正在尝试编写一个逻辑应用程序来解析 Json 对象并更新 salesforce 记录。我对 Salesforce 和 Azure 逻辑应用程序都很陌生,所以我正在尝试解决这个问题。下面是我的 Json 文件

{
"ContactId": null,
"Email": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e485978b8a83a4918b83ca878b89" rel="noreferrer noopener nofollow">[email protected]</a>",
"IsInternalUpdate": false,
"Preferences": [
{
"PrefCode": "EmailOptIn",
"CurrentValue": "Yes",
"Locale": "en-US"
},
{
"PrefCode": "MobilePhone",
"CurrentValue": "1234567890",
"Locale": "en-US"
},
{
"PrefCode": "SMSOptIn",
"CurrentValue": "Yes",
"Locale": "en-US"
},
{
"PrefCode": "ProductTrends",
"CurrentValue": "ProductTrends,OffersPromotions",
"Locale": "en-US"
},
]
}

根据电子邮件值,我需要更新 Salesforce 中的自定义对象。从首选项数组中,预编码值映射到 Salesforce 中的字段,当前值映射到字段值。即下面的代码片段将 Salesforce 中的 EmailOptIn 字段的值设置为"is"

    {
"PrefCode": "EmailOptIn",
"CurrentValue": "Yes",
"Locale": "en-US"
}

到目前为止,我能够传递硬编码值并成功从逻辑应用更新 salesforce 记录。

我正在尝试为每个字段设置单独的变量,以便我可以将其直接传递给 salesforce。我遇到了两个问题

  1. 捕获字段值映射的最佳方式是什么?
  2. 我有几个允许多选的字段,如何设置多选值。下面是一个例子
{
"PrefCode": "ProductTrends",
"CurrentValue": "ProductTrends,OffersPromotions",
"Locale": "en-US"
}

下面是我的逻辑应用结构

1

2

最佳答案

  1. What is the best way to capture the field value mapping?

我可以通过构造具有所需详细信息的 JSON 并再次使用解析 JSON 步骤来实现您的要求。以下是对我有用的逻辑应用程序的流程。

enter image description here

enter image description here

  1. I have couple of fields that allow multi select, how do I set the multiselect values. Below is an example

我已将 ProductTrends 转换为数组,并使用其索引检索每个项目,如下所示。

array(split(body('Parse_JSON_2')?['ProductTrends'],','))[0]
array(split(body('Parse_JSON_2')?['ProductTrends'],','))[1]

或者,如果可以使目标端的多个值正常工作,您可以将数组或字符串直接发送给 salesforce。

下面是我的逻辑应用的完整 JSON。

{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": {
"ContactId": null,
"Email": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6405170b0a0324110b034a070b09" rel="noreferrer noopener nofollow">[email protected]</a>",
"IsInternalUpdate": false,
"Preferences": [
{
"CurrentValue": "Yes",
"Locale": "en-US",
"PrefCode": "EmailOptIn"
},
{
"CurrentValue": "1234567890",
"Locale": "en-US",
"PrefCode": "MobilePhone"
},
{
"CurrentValue": "Yes",
"Locale": "en-US",
"PrefCode": "SMSOptIn"
},
{
"CurrentValue": "ProductTrends,OffersPromotions",
"Locale": "en-US",
"PrefCode": "ProductTrends"
}
]
},
"runAfter": {},
"type": "Compose"
},
"Compose_2": {
"inputs": "@array(split(body('Parse_JSON_2')?['ProductTrends'],','))[0]",
"runAfter": {
"Parse_JSON_2": [
"Succeeded"
]
},
"type": "Compose"
},
"For_each": {
"actions": {
"Append_to_string_variable": {
"inputs": {
"name": "Preferences",
"value": "\"@{items('For_each')?['PrefCode']}\":\"@{items('For_each')?['CurrentValue']}\",\n"
},
"runAfter": {},
"type": "AppendToStringVariable"
}
},
"foreach": "@body('Parse_JSON')?['Preferences']",
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "Foreach"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "Preferences",
"type": "string"
}
]
},
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Parse_JSON": {
"inputs": {
"content": "@outputs('Compose')",
"schema": {
"properties": {
"ContactId": {},
"Email": {
"type": "string"
},
"IsInternalUpdate": {
"type": "boolean"
},
"Preferences": {
"items": {
"properties": {
"CurrentValue": {
"type": "string"
},
"Locale": {
"type": "string"
},
"PrefCode": {
"type": "string"
}
},
"required": [
"PrefCode",
"CurrentValue",
"Locale"
],
"type": "object"
},
"type": "array"
}
},
"type": "object"
}
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "ParseJson"
},
"Parse_JSON_2": {
"inputs": {
"content": "@concat('{',slice(variables('Preferences'),0,lastIndexOf(variables('Preferences'),',')),'}')",
"schema": {
"properties": {
"EmailOptIn": {
"type": "string"
},
"MobilePhone": {
"type": "string"
},
"ProductTrends": {
"type": "string"
},
"SMSOptIn": {
"type": "string"
}
},
"type": "object"
}
},
"runAfter": {
"For_each": [
"Succeeded"
]
},
"type": "ParseJson"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}

按照上述过程后,我可以单独获取偏好值。

enter image description here

关于json - 将 JSON 数组解析为 Azure 逻辑应用中的各个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75253757/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com