1

我对 powerapps 很陌生,但边走边学。有没有办法将以下 if 语句写成一个语句?(这样它只会在我的共享点列表中创建一个项目,而不是为每个 if 语句创建单独的项目)。我正在努力这样做,因为每个 If 语句都有不同的默认结果。

If(
    IsEmpty(MondayCombo.SelectedItems),
    Patch(
        ChangeOfService,
        Defaults(ChangeOfService),
        {Monday: DataCardValue82.Text}
    ),
    Patch(
        ChangeOfService,
        Defaults(ChangeOfService),
        {
            Monday: Concat(
                MondayCombo.SelectedItems,
                Value,
                ", "
            )
        }
    )
);
If(
    IsEmpty(TuesdayCombo.SelectedItems),
    Patch(
        ChangeOfService,
        Defaults(ChangeOfService),
        {Tuesday: DataCardValue83.Text}
    ),
    Patch(
        ChangeOfService,
        Defaults(ChangeOfService),
        {
            Tuesday: Concat(
                TuesdayCombo.SelectedItems,
                Value,
                ", "
            )
        }
    )
);
If(
    IsEmpty(WednesdayCombo.SelectedItems),
    Patch(
        ChangeOfService,
        Defaults(ChangeOfService),
        {Wednesday: DataCardValue84.Text}
    ),
    Patch(
        ChangeOfService,
        Defaults(ChangeOfService),
        {
            Wednesday: Concat(
                WednesdayCombo.SelectedItems,
                Value,
                ", "
            )
        }
    )
);
If(
    IsEmpty(ThursdayCombo.SelectedItems),
    Patch(
        ChangeOfService,
        Defaults(ChangeOfService),
        {Thursday: DataCardValue85.Text}
    ),
    Patch(
        ChangeOfService,
        Defaults(ChangeOfService),
        {
            Thursday: Concat(
                ThursdayCombo.SelectedItems,
                Value,
                ", "
            )
        }
    )
);
4

1 回答 1

1

不幸的是,PowerApps 还没有returnorexit命令来中断代码执行。

您必须想出一个解决方法来验证代码执行并绕过所有其他不需要的代码执行。例如,我们可以有一个布尔变量在下一个循环中设置和验证。

UpdateContext({RecordCreated:false});
If(
    IsEmpty(MondayCombo.SelectedItems),
    UpdateContext({RecordCreated:true});
    Patch(
        ChangeOfService,
        Defaults(ChangeOfService),
        {Monday: DataCardValue82.Text}
    ),
    UpdateContext({RecordCreated:true});
    Patch(
        ChangeOfService,
        Defaults(ChangeOfService),
        {
            Monday: Concat(
                MondayCombo.SelectedItems,
                Value,
                ", "
            )
        }
    )
);
If(RecordCreated = false,
If(
    IsEmpty(TuesdayCombo.SelectedItems),
    Patch(
        ChangeOfService,
        Defaults(ChangeOfService),
        {Tuesday: DataCardValue83.Text}
    ),
    Patch(
        ChangeOfService,
        Defaults(ChangeOfService),
        {
            Tuesday: Concat(
                TuesdayCombo.SelectedItems,
                Value,
                ", "
            )
        }
    )
);)

请投票赞成这个想法

于 2019-12-05T21:29:43.393 回答