Hi community,
i have save button in my app and i want it to save into two separate SPO lists,
NeedToSave and VarStatus are two variables that evaluate whether the user made changes that need to be saved and then save it.
it should save to either one of them or to both based on the varailables evaluated to true.
but only the first part of the formula is working and saving to the VP Weekly Status table, the other part is not saved although the VarStatus variable is true.
when taking the second part of the formula into a separate button (not withon an if statement) it works just fine.
any ideas?
my formula:
If(NeedToSave,
ClearCollect(
UpdatedItems,
ItemsGallery.AllItems
);
ForAll(UpdatedItems, Patch(
'VP weekly status',
LookUp('VP weekly status',ID=UpdatedItems[@ID]),
{Report_Items:TextInput3.Text},
{Week:WeekValVP},
{DataType:{
'@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
Value: ItemType,
ID:ItemsGallery.Selected.ID
}}
)),
varStatus,
ForAll(
Gallery2_1.AllItems,
Patch(AccountsWeeklyStatus,ThisRecord,{Status:{ Value:LblUpdatedStatus_1.Text},'Status Description':TxtStatusDesc.Text}))
)
thanks, it worked!!
Just chiming in here because I noticed in your formula that you were wasting the output of the ForAll. ForAll is a function that returns a table - it is too overused as a programming For/Next and the results wasted. This also impacts performance.
Consider the following formula for what you need:
If(NeedToSave,
Patch(
'VP weekly status'
ForAll(ItemsGallery.AllItems As _item,
LookUp('VP weekly status',ID=UpdatedItems[@ID]),
{ID: _item.ID,
Report_Items: _item.TextInput3.Text,
Week: WeekValVP,
DataType:{Value: ItemType, ID:ItemsGallery.Selected.ID}
}
)
)
);
If(varStatus,
Patch(AccountsWeeklyStatus,
ForAll(Gallery2_1.AllItems As _item,
{ID: _item.ID,
Status: {Value:_item.LblUpdatedStatus_1.Text},
'Status Description': _item.TxtStatusDesc.Text
}
)
)
)
HOWEVER... @WarrenBelz was spot on, and deserves the solution for this, that you had your second part in the else of the If. So, this would never work to do both conditions. It would have only done NeedToSave (if true) or varStatus (if NeedToSave was false and varStatus was true).
I hope this is helpful for you.
@WarrenBelz , thanks for the quick reply.
i tried your formula, and it gives set of errors.
can you please elaborate about the use of the With function and As operator.
as for my original formula in the UI it looks like it is the true value for the second logical test
Hi @Perez ,
That is because you have the second Patch as the "else" of the If() statement - try this (note you do not need the odata.type reference any more)
If(
NeedToSave,
With(
{wItems:ItemsGallery.AllItems},
ForAll(
wItems As aPatch,
Patch(
'VP weekly status',
{ID=aPatch.ID},
{
Report_Items:TextInput3.Text,
Week:aPatch.WeekValVP,
DataType:
{
Value: aPatch.ItemType,
ID:ItemsGallery.Selected.ID
}
}
)
)
)
);
If(
varStatus,
ForAll(
Gallery2_1.AllItems,
Patch(
AccountsWeeklyStatus,
ThisRecord,
{
Status:{Value:LblUpdatedStatus_1.Text},
'Status Description':TxtStatusDesc.Text
}
)
)
)
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.
WarrenBelz
146,524
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,906
Most Valuable Professional