一个 If 语句,不同的默认结果
One If Statement, different default result
我对 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,
", "
)
}
)
);
不幸的是,PowerApps 还没有 return
或 exit
命令来中断代码执行。
您必须想出一个解决方法来验证代码执行并绕过所有其他不需要的代码执行。例如,我们可以有一个 bool 变量来在下一个循环中设置和验证。
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,
", "
)
}
)
);)
请点赞this idea
我对 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,
", "
)
}
)
);
不幸的是,PowerApps 还没有 return
或 exit
命令来中断代码执行。
您必须想出一个解决方法来验证代码执行并绕过所有其他不需要的代码执行。例如,我们可以有一个 bool 变量来在下一个循环中设置和验证。
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,
", "
)
}
)
);)
请点赞this idea