I am using the below code to patch the records.
some time user forgets to input the Qty and click on the button, The records get posted with Blank Qty.
I want to stop patch code to run if the RecQty of any of the row is Null or Empty
I want notification that it cannot post ,
Please advise what correction to be done in the below code to obtain this result
hey @MIA27
try this instead:
If(
CountRows(
Filter(
Gallery9.AllItems,
IsBlank(TextBox4.Value) || Value(TextBox4.Value) = 0
)
) > 0,
Notify("Cannot post record because one or more Received Quantities are empty or zero.", NotificationType.Error),
ForAll(
Gallery9.AllItems,
Collect(
colAllPartsReceipt,
Patch(
TablePartsReceipts,
Defaults(TablePartsReceipts),
{
RecoNo: (First(Sort(TablePartsReceipts, RecoNo, SortOrder.Descending)).RecoNo) + 1,
RecDate: DatePicker4.Value,
PartNumber: Upper(Label21.Text),
PartDescription: Upper(Label24.Text),
RecQty: Value(TextBox4.Value),
UnitCost: Value(TextBox4_1.Value),
Vendor: Upper(TextBox4_2.Value),
RecRemarks: Upper(TextBox4_3.Value)
}
)
)
)
);
Ok, so I think that if you do the check for invalid items first, then only patch once that is validated, that should handle the condition you've mentioned:
Clear(numberOfInvalidRows);
ForAll(
Gallery9.AllItems,
If(
IsBlank(TextBox4.Value) || Value(TextBox4.Value) = 0,
Collect(numberOfInvalidRows, ThisRecord)
)
);
If(
CountRows(numberOfInvalidRows)>0,
Notify("Cannot post record because one of the Received Quantity rows is empty or zero.", NotificationType.Error),
ForAll(
Gallery9.AllItems,
Collect(colAllPartsReceipt,
Patch(
TablePartsReceipts, Defaults(TablePartsReceipts),
{
RecoNo:(First(Sort(TablePartsReceipts, RecoNo, SortOrder.Descending)).RecoNo)+1,
RecDate:DatePicker4.Value,
PartNumber:Upper(Label21.Text),
PartDescription:Upper(Label24.Text),
RecQty:Value(TextBox4.Value),
UnitCost:Value(TextBox4_1.Value),
Vendor:Upper(TextBox4_2.Value),
RecRemarks:Upper(TextBox4_3.Value)
}
)
)
)
);
Thank you for your advised code. I applied and it worked, But not the way I wanted.
For example you can note in the below image I kept 3 records together to test.
In first I kept RecQty,
Second I kept Blank to check error notification,
Third I kept the RecQty
Code ran, it added first and third record and brought the error notification due to second record.
But as I mentioned It will create confusion which record etc, I mean, I want
If any of the record has RecQty Blank or 0 THEN the code should exit, not run further from the Fx -
I dont want to run the patch for the other records , or run any code in that property of Fx.
Simply it should exit path as well any code after that.
This will push user first to fix the RecQty and then run the patch all
Kindly guide the modified code.
You can use what @mmbr1606 suggested.
That is:
ForAll(
Gallery9.AllItems,
If(
IsBlank(TextBox4.Value) || Value(TextBox4.Value) = 0,
Notify("Cannot post record because the Received Quantity is empty or zero.", NotificationType.Error),
Collect(
colAllPartsReceipt,
Patch(
TablePartsReceipts,
Defaults(TablePartsReceipts),
{
RecoNo: (First(Sort(TablePartsReceipts, RecoNo, SortOrder.Descending)).RecoNo) + 1,
RecDate: DatePicker4.Value,
PartNumber: Upper(Label21.Text),
PartDescription: Upper(Label24.Text),
RecQty: Value(TextBox4.Value),
UnitCost: Value(TextBox4_1.Value),
Vendor: Upper(TextBox4_2.Value),
RecRemarks: Upper(TextBox4_3.Value)
}
)
)
)
);
:
hey @MIA27
please try this:
ForAll(
Gallery9.AllItems,
If(
IsBlank(TextBox4.Value) || Value(TextBox4.Value) = 0,
Notify("Cannot post record because the Received Quantity is empty or zero.", NotificationType.Error),
Collect(
colAllPartsReceipt,
Patch(
TablePartsReceipts,
Defaults(TablePartsReceipts),
{
RecoNo: (First(Sort(TablePartsReceipts, RecoNo, SortOrder.Descending)).RecoNo) + 1,
RecDate: DatePicker4.Value,
PartNumber: Upper(Label21.Text),
PartDescription: Upper(Label24.Text),
RecQty: Value(TextBox4.Value),
UnitCost: Value(TextBox4_1.Value),
Vendor: Upper(TextBox4_2.Value),
RecRemarks: Upper(TextBox4_3.Value)
}
)
)
)
);
Let me know if my answer helped solving your issue.
If it did please accept as solution and give it a thumbs up so we can help others in the community.
Greetings
Try using IsBlank - or in this case !IsBlank (Not IsBlank)
e.g. if(!IsBlank((TextBox4.Value), Patch .... etc
Rgds
Nigel
Dear Vishal,
Notification line can be added at the end.
But what code to add to check if any of the row's RecQty is null, before patching
pls guide
You can use the NOTIFY Function to show the notification about it not being posted.
WarrenBelz
146,658
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,999
Most Valuable Professional