我在 Microsoft Form 中收集了信息,我想使用 Power Automate 通过电子邮件发送该信息。
表单数据将是这样的(字段名称:值):
公司网站:是
公司新闻:是的
企业新闻标题:这是我们的新闻故事
公司BannerEnd:空
公司页面:否
公司页面URL:空
我不想包含 null 或“no”字段,因此在这个示例中,我想要的输出是:
公司网站:是
公司新闻:是的
企业新闻标题:这是我们的新闻故事
我知道如何将表单结果输入 Power Automate,以及如何发送电子邮件,但我正在尝试找到一种不笨拙的方法来在许多字段可能为空时获得干净的电子邮件内容。
表单数据分为三个主要部分,每个部分都有一个是/否问题,指示该部分中是否有内容。因此,如果用户选择“是”,可以很容易地为三个部分中的每一个部分使用一个条件,仅包含该部分的内容(上面的示例显示了表单“公司网站”部分中的一些问题)。
当我的条件为“是”时,我想遍历该部分中的字段并收集包含内容的字段,如上面我想要的输出所示。我认为这样的方法可以测试每个字段并包含该值(如果有的话):
if(empty(outputs('Get_response_details')?['body/r008aa103d6044ae19833da19494676e0']), null, outputs('Get_response_details')?['body/r008aa103d6044ae19833da19494676e0'])
我可以在电子邮件中使用一大堆“if”表达式(每个表单字段一个),但似乎只运行公司表达式会更有效,例如,如果公司条件是遇见:
不过,我不确定使用什么控件来“保存”每个字段的 if 语句,然后获取需要包含在电子邮件中的输出。我尝试使用文本变量,但是当我刚刚粘贴上面的代码时,它会逐字返回(电子邮件包含代码,而不是代码的输出)。当我尝试将上述内容作为函数包含时,没有输出。
那么,如何获得合适的字段来显示电子邮件中的一行文本?
编辑/更新:这是表单响应 JSON 的样子。
我不希望电子邮件包含以“”作为响应的字段,以及其他一些仅用于促进表单导航但不提供与满足请求相关的任何信息的其他字段。
如果有帮助,我可以调整表单响应选项,以便只有不应包含在电子邮件中的字段才有以“是”或“否”开头的答案。
"body": {
"responder": "zzz",
"submitDate": "1/13/2025 4:55:58 PM",
"r22a00717441f472b885badc71fdb2de1": "None of the above, and no meeting is required",
"r33a4f1266d9b4ef2858148f7c370f517": "No",
"rc254ffe7f8d447978c36c610d9f89cf3": "2025-01-16",
"rc533ab68aaf745e98d9ac19c968a420f": "Sample Request",
"r64e954319c6b4326b7f11e7edcabf514": "Webel publishes and informs the Advisor",
"r88fb7e09975742a49901b9537586598e": "Sample Story Request",
"r31b78ff0ab9640498942ed4f3ad8d162": "You'll love this sample news story, full of words and a picture",
"r4aaa4e35d4aa4a16b2fd1172604cac5b": "a group of happy students",
"rf5560b79448949fd9dd44993d03a45d7": "John Doe",
"r3b94cc1d1d0b45b38717fb3c5392f507": "",
"r198cf5797bfa4a719b6e243a4a768854": "",
"rc8f3d7483ba7447d9e36350fa94e4e50": "",
"r37d92ffffc5c4f4db03deaf10eaf72d8": "",
"r75aa2e1c4d6d4df3a692b49ef9cfe541": "sample.url/page",
"r6fe1c5aed7c54e8f9b49f33d1f9edfef": "Please replace the graphic with the one requested for the news story",
"rb940f08155c045b1af24efd8d0c3cd54": "",
"r3a20300a86ba42a884b81c03013d58f7": "",
"r1cd2338d8da04e2b8f068b9f5c53843d": "",
"r799a1b00b9304cd0afb80ab49f71d0a2": "Non-banner",
"rad4ba23c35db44859d9603ebcf75993d": "",
"r7ae3c6aab9b3438cb705d4f13d073007": "",
"r57ba068b40a04d3d9e99c64940cbd44a": "",
"r9ee7489c59a9431681ef4dbfd3c53ff2": "Yes",
"r49e6c28f45a54ec9a176931aa638d7a0": "Yes",
"rc943baef494a4ba3a870c62acdde3068": "Yes",
"r4eacc1bafa124dd184475e21855b96ab": "",
"r74214995486d4dfe9480426aaeb71e0f": "Yes, other corporate site components",
"rcd630471ec1a48fcb5d0c5acbdc77f7d": "",
"r79c0eed8f1b64ad8ae4a7faffe219a59": "",
"r5dd7226f71da4369a1acca8fad9d5651": "Yes, but not for the corporate site",
"rb37f681768ab4e78a2e9b65fbe2c979f": "",
"rc8e1feae50db429db8815aa8f5bd959e": "",
"r787c00f85cc94f3891e9a16594aff0b5": "",
"r156ad4e9e15f4de896eb318e156d4935": "",
"r0e3ebf63dbc349efb02d7b36c1a501be": "",
"r85490e9748a14ec0bfb45e5e6333bc4d": "",
"r05627f01fadd4bbdbff5b969afc543d1": "",
"r9255e6818106430b9a7886387b51c8de": "",
"r46931e1013d848498751ec59d7227407": "",
"r53582d2a762b41659ec8644c08453c28": "",
"r193c6b1dc8d944859375c5df545cd748": "",
"r086468a6f7394fee9652a7f4a08b90aa": "",
"rd504c0bc5c0a470d8aa915b9163ea911": "",
"r7aebff3258894c0cbbd789d96c071fb9": "",
"rfd08983ad3ef4d5298362cc57719969f": "",
"r1f1ecf42d3fe4e6881750d6dd686495e": "",
"re098869c7820431aae68d0f4ab100986": "",
"rebdb9f700e3642ac992fbe3e081fdb25": "",
"ra8b9a502cd3947f084056726beb3bfb1": "",
"rd4fc40f0d261457a88c9a8e3c387edeb": "",
"r42d96cc8ac9d41f3a626564445b4e879": "",
"r8d9734799eb141b9b3b84aa8cb986c87": "",
"rb7b59df9c1974facb4e4a216a21a9dad": "",
"rc761d35862f84286b27f5c1d947b7bf5": "",
"rd79fc1d0ee774e7ab5b8efe7db8f3981": "",
"r0e60d284e88042caaf973300ccf5c6f0": "",
"r717fef2877f043488b5ff14aee5d94ac": "",
"r1f59a6efe9144313be397d9474c2cdc6": "",
"r1d1eb6f163014ad5b84727a2194c7b39": "",
"r226502c0a9274c5c9044d7fc54382c7a": "",
"r3342647606944b5d9bb3bc05f055e9d8": "No",
"rd46db32581a0426092e674a133f10036": "Yes",
"r230f5d84bf204ed8ae44ae2475d31dba": "",
"r4ab1cab232644bbc9935de7d9eb1c477": "",
"r25fd6d077f734204ba67aba0a2dd8b22": "",
"rb515c1a1b9ac4719aa3e45a431119c22": "",
"ra9da7c2158ee430ea221a403c20423db": "",
"r008aa103d6044ae19833da19494676e0": "",
"rcde6dd1823d74ca09cae59184682db6a": "",
"r764f4a7f630d47c69e9fa5e68844bb97": "",
"re62886ed4dad480f8a5e507ace836ec3": "No",
"r070626538cb442c69b312bf063a3ff72": "",
"r8ddddcfa436949efa95085e9ef4c1cd1": "",
"re341fcc8e0bd484f84de51d4e69e97e0": "",
"r423b69e132e143ebb979b6c884bae1ba": "Yes",
"r25c480ae73174d0eb1f80d620858c052": "Modify an existing document",
"re6d39c588f8e46c19e09973aceba5447": "sample.url/document",
"r691a2307cd2941beaa88c4152dbcbb08": "Please change the heading to H1",
"r9046b9ccc38b4bcc923edcfe635cdcd2": "No other components to my request",
"r9fee67532a8a42beb6c9634899dfda8b": "",
"r69ced8e70d37441b83a2e0d443179e6b": "",
"r9a462f887c154e7dab111d74c6b02a20": "",
"rc79ee7c66da94c549d40f68d91cb6977": "",
"r17e3746959e7412cac184b6cc0737083": "",
"rd1eb7be6ff734695ba0ddd7de7f50d06": "",
"r5afec204c3e54f58b390092e692ef121": "",
"reee1cdfd97ad4777aed5437ea33b12c6": "",
"rfaa2e592fb954054b0966853f1804999": "",
"r737c3cd0d40847ab87bdc92e0bfed779": "No other components, take me to the last question",
"r26436c57b5254e529586ba91d531fb55": "",
"r1fc329cff7274ed8abb247831bc119d4": "",
"re4be7860dbfb4a6b9ffd0c6960fb7f06": "",
"r1a3e29e151884e67a1cc61adce470011": "",
"ra426896adcef47d4970512d50f62e347": "",
"r4c8bc1fa8d6e49f7ba81d27784417c41": "",
"r22a572bac6d84e79a27c2f59d17be4d5": "",
"r7cc8f340f5e64ff7be556940eda4986c": "No",
"rb192b97df860450ba280e4306732b3c8": "",
"rdeea55f9c47b489babbb762f9fd51948": "No preference"
}
}
该解决方案本质上将响应从对象转换为一系列问题/答案,然后可以对其进行过滤,并最终转换为 HTML 表格以添加到您的电子邮件中。
首先,您需要一个数组来保存问题 ID 及其标签。您需要手动完成此步骤,并按照您希望在电子邮件中显示的顺序执行此操作。 添加
Compose
操作并将其命名为 aQuestions
,最好在 Get response details
步骤之前。
[
{ "id": "r008aa103d6044ae19833da19494676e0", "label": "Corporate Site" },
{ "id": "rcde6dd1823d74ca09cae59184682db6a", "label": "Label Alpha" },
{ "id": "r764f4a7f630d47c69e9fa5e68844bb97", "label": "Label Bravo" },
{ "id": "re62886ed4dad480f8a5e507ace836ec3", "label": "Label Charlie" },
{ "id": "r070626538cb442c69b312bf063a3ff72", "label": "Label Delta" }
]
这只是数组结构的演示,您将有更多记录等...注意最后一个不要在末尾有逗号。这是一个记录(对象)的 JSON 数组。
下一步,在 Get response details
步骤之后,添加
Select
操作(在数据操作下),并将其重命名为 aResponses
。From: outputs('aQuestions')
Map:
Question: item()?['label']
Response: outputs('Get_response_details')?['body']?[item()?['id']]
它应该看起来像:接下来,添加一个
Filter array
操作(在数据操作下),并将其重命名为
aResponsesFiltered
,内容如下:From: @body('aResponses')
Filter: @and(not(equals(item()?['Response'], 'No')), not(equals(item()?['Response'], '')))
通过
Edit in advance mode
添加过滤器。它应该看起来像:
这会删除""
或 "No"
的响应。您还可以使用此替代过滤器:
@not(contains(item()?['Response'], array('No', '')))
Create HTML table
(在数据操作下):
From: body('aResponsesFiltered')
Columns: Automatic
最后,将此步骤的输出添加到您的电子邮件中。这是我的模型,仅用于演示目的(我的
Get response details
是你的模仿品)。