更新阵列列电源自动化流程

问题描述

在我的云流程中,我需要检查每个日期列并使用距今天日期 7 天内的列名称更新“ActiveDate”。

所以对于下面的示例,我希望用值“Date1”填充 ActiveDate

{
    "RPTID": "RPT4072","Date1": "2021-07-02","Date2": "2021-09-17","Date3": "2021-10-22","Date4": "2022-02-25","Date5": "2022-05-20","Date6": "2023-03-07","ActiveDate": "","ProjectManager": "TBC","QuantitySurveyor": "Mr A / Mr B"
  }

我觉得我在兜兜转转,试图弄清楚如何做到这一点。我尝试过 IF 语法和 Condition 操作,但似乎无法获得正确的逻辑。非常感谢任何帮助。

以下是excel的源码和SELECT。

first section

然后我添加一个循环并尝试使用各种选项更新日期计算,但都没有奏效。

second part

上面的截图抛出这个错误

InvalidTemplate. Unable to process template language expressions in action 'Compose_2' inputs at line '1' and column '43252': 'In function 'formatDateTime',the value provided for date time string 'Date3' was not valid. The datetime string must match ISO 8601 format.'.

这里有几个错误让我继续尝试上面的整数指针:

'The template language expression 'div(sub(ticks(formatDateTime(body('Select')[item()],'yyyy-MM-dd')),ticks(formatDateTime(substring(utcNow(),10),'yyyy-MM-dd'))),864000000000)' cannot be evaluated because property 'Date1' cannot be selected. Array elements can only be selected using an integer index.

'The template language expression 'div(sub(ticks(formatDateTime(variables('dates')[item()],864000000000)' cannot be evaluated because property 'Date1' cannot be selected. Array elements can only be selected using an integer index.

Unable to process template language expressions in action 'Compose_4' inputs at line '1' and column '43252': 'The template language expression 'items('Apply_to_each')?[item()]' cannot be evaluated because property 'Date1' cannot be selected. Property selection is not supported on values of type 'String'

我觉得它需要某种 item().value 但对于我的生活我无法得到它..

解决方法

棘手的部分是计算每个日期的日期差异,然后更新 json 对象中的属性。

日期差计算

div(sub(ticks(formatDateTime(variables('Result')[item()],'yyyy-MM-dd')),ticks(formatDateTime(substring(utcNow(),10),'yyyy-MM-dd'))),864000000000)

更新 Json 对象中的属性

setProperty(variables('result'),'ActiveDate',variables('FinalDate'))

假设您将 json 对象放在一个变量中。我正在为此初始化一个变量 Result。除此之外,您需要一个变量 FinalDate 来存储所需的日期,另一个变量 Dates 来存储您的 6 个日期键。

enter image description here

现在您需要遍历所有日期键并找到每个日期的日期差异并检查它是否在 -7 enter image description here

现在你只需要更新你原来的 json 对象。您可以简单地使用 setProperty 方法来执行此操作,如下所示。 enter image description here