У меня есть набор данных, который выглядит примерно так, как показано ниже:
[
{
"Ref": "B0048",
"Desc": "Electricity Management",
"User": {
"@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
"Claims": "i:0#.f|membership|[email protected]",
"DisplayName": "Gary",
"Email": "[email protected]",
"Department": "N/A",
"JobTitle": "Big Boss"
}
},
{
"Ref": "B0049",
"Desc": "New Hardware Business Case",
"User": {
"@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
"Claims": "i:0#.f|membership|[email protected]",
"DisplayName": "Martin@example",
"Email": "[email protected]",
"Department": "Maintenance",
"JobTitle": "Maintenance Manager"
}
},
{
"Ref": "B0050",
"Desc": "Estimating Tool",
"User": {
"@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
"Claims": "i:0#.f|membership|[email protected]",
"DisplayName": "Toni",
"Email": "[email protected]",
"Department": "Construction",
"JobTitle": "Construction Manager"
}
},
{
"Ref": "B0050",
"Desc": "Estimating Tool",
"User": {
"@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
"Claims": "i:0#.f|membership|[email protected]",
"DisplayName": "Rob",
"Email": "[email protected]",
"Department": "Construction",
"JobTitle": "Construction Coordinator"
}
},
{
"Ref": "B0051",
"Desc": "New Software Business Case",
"User": {
"@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
"Claims": "i:0#.f|membership|[email protected]",
"DisplayName": "Gary",
"Email": "[email protected]",
"Department": "N/A",
"JobTitle": "Big Boss"
}
}
]
Следует отметить, что в некоторых случаях на одного человека приходится несколько проектов, а в других на один проект приходится несколько человек. Я собираюсь использовать Power Automate для перестановки компонентов для получения следующего вывода, чтобы я мог генерировать целевые сообщения...
[
{
"DisplayName": "Gary",
"Email": "[email protected]"
"Project": {
"Ref": "B0048",
"Desc": "Electricity Management"
},
{
"Ref": "B0051",
"Desc": "New Software Business Case"
}
},
{
"DisplayName": "Martin",
"Email": "[email protected]"
"Project": {
"Ref": "B0048",
"Desc": "Electricity Management"
}
},
{
"DisplayName": "Toni",
"Email": "[email protected]"
"Project": {
"Ref": "B0050",
"Desc": "Estimating Tool"
}
},
{
"DisplayName": "Rob",
"Email": "[email protected]"
"Project": {
"Ref": "B0050",
"Desc": "Estimating Tool"
}
}
]
Я пробовал много комбинаций Select, Filter Array, Append to Array, используя циклы Apply to Each. До сих пор я либо получаю сообщение об ошибке, либо успешный поток выдает бесполезный вывод (или его вообще нет).
Я слишком долго возился в темноте, пытаясь заставить это работать, и на самом деле ничего не добился, поэтому я решил, что было бы гораздо более продуктивно использовать время, чтобы попросить мозговой трест о каком-то направлении!



Лучшее, что я смог придумать, это следующий формат без использования циклов:
[
{
"DisplayName": "Gary",
"Email": "[email protected]",
"ProjectRef": [
"B0048",
"B0051"
],
"ProjectDesc": [
"Electricity Management",
"New Software Business Case"
]
},
{
"DisplayName": "Martin@example",
"Email": "[email protected]",
"ProjectRef": [
"B0049"
],
"ProjectDesc": [
"New Hardware Business Case"
]
},
{
"DisplayName": "Toni",
"Email": "[email protected]",
"ProjectRef": [
"B0050"
],
"ProjectDesc": [
"Estimating Tool"
]
},
{
"DisplayName": "Rob",
"Email": "[email protected]",
"ProjectRef": [
"B0050"
],
"ProjectDesc": [
"Estimating Tool"
]
}
]
Если это достаточно близко, то вот шаги:
Подробности:
Step: JsonInput
Action: Compose
Inputs: Your starting Json above.
Step: toXML
Action: Compose
Inputs:
xml(json(concat('{"payload":{"projects":', string(outputs('JsonInput')), '}}')))
Step: Select
Action: Select
From:
union(xpath(outputs('toXML'), '//User/Email/text()'), json('[]'))
Map:
DisplyName:
xpath(
outputs('toXML'),
concat('(//User/Email[text() = "', item(), '"])[1]/../DisplayName/text()')
)?[0]
Email:
item()
ProjectRef:
xpath(
outputs('toXML'),
concat('//User/Email[text() = "', item(), '"]/../../Ref/text()')
)
ProjectDesc:
xpath(
outputs('toXML'),
concat('//User/Email[text() = "', item(), '"]/../../Desc/text()')
)
Примечания:
НП, если ответ вам подходит, помогите отметить его как «Принятый» для всеобщего блага (нажмите галочку под кнопками голосования: i.sstatic.net/97kjx.png)
Удивительно, спасибо за помощь Сэму!!