Pls let me know what is wrong with the below code
I'm checking two collections and if both are empty, I want the error to prompt.
But now it is validating this code and submitting the form even if the collections is empty
If(
CountRows(
Filter(NewCollection,
Or(
IsBlank(A),
IsBlank(B),
IsBlank(C)
)
)
) &&
CountRows(
Filter(EditCollection,
Or(
IsBlank(D),
IsBlank(E),
IsBlank(F)
)
)
) > 0 ,
Notify(
"Admin Role is required",
Error
),
SubmitForm(Form))
Hi ,
So did more testing with a label to check what I'm getting for the Count Rows and found the reason. Nothing wrong with my code or yours, I was getting another result due to what is in my collection.
So achieved what I'm trying to find with IsEmpty condition in addition to Count Rows. Going to do more testing
Thanks @RandyHayes @WarrenBelz
Hi Randy
So I have two Collections in the Edit Mode. So what I want to check is if both are empty. If not then it is success. Meaning if Edit collection is not empty then it is success.
I tested with your code. Getting the same result
Maybe I need to amend to check the Edit collection are empty first and if so then check the New collection if not success
CountRows returns a number. This is what was wrong with your original formula...you were trying to perform a logical AND between two numbers.
Plus will add two numbers. In this case, the resultant number from the CountRows. The two products are added together. If there is any countrow that returns more than 0, then it will be added as the result. THEN, your real logic is to see if that number is > 0.
Please change your Formula to the following:
If(
Form.Mode = FormMode.New,
If(CountRows(Filter(NewCollection, IsBlank(A) || IsBlank(B) || IsBlank(C))) > 0,
Notify("Admin Role is required", Error),
Notify("Success", Error)
),
Form.Mode = FormMode.Edit,
If(
(
CountRows(Filter(NewCollection, IsBlank(A) || IsBlank(B) || IsBlank(C))) +
CountRows(Filter(EditCollection, IsBlank(D) || IsBlank(E) || IsBlank(F)))
) > 0,
Notify("Admin Role is required", Error),
Notify("Success", Error)
)
)
What does + means .. is it checking both are empty?
I want to continue submitting if one is not, In that case will it be the same?
Hi
The code for the Form.Edit part is still not working .
Even if the Edit collections is not Empty it is not submitting the form when the NEW collection is empty.
I tried testing by changing "||" to "&&". It does submit the EDIT Collection when I changed to that but when I delete all the records in the collection it does submit like that too without ANY collections data.
If I put the same collections twice in the code it is working but if I put the two collection, it just say missing New Collection.
Even if EDIT Collection is not there, NEW collection can be submitted but NOT the other way around.
If(Form.Mode = FormMode.New,
If(
CountRows(
Filter(NewCollection,
Or(
IsBlank(A),
IsBlank(B),
IsBlank(C)
)
)
) > 0,
Notify(
"Admin Role is required",
Error
),
Notify(
"Success",
Error
)
),
Form.Mode = FormMode.Edit,
If(
CountRows(
Filter(
NewCollection,
IsBlank(A) || IsBlank(B) || IsBlank(C)
)
) > 0 ||
CountRows(
Filter(
EditCollection,
IsBlank(D) || IsBlank(E) || IsBlank(F)
)
) > 0,
Notify(
"Admin Role is required",
Error
),
Notify(
"Success",
Error
)
);
)
Yes...sleeping! Start of a Sunday morning here now.
Did you try the formula I provided you? (slightly revised version below)
If(
(
CountRows(Filter(NewCollection, Or(IsBlank(A), IsBlank(B), IsBlank(C)))
+
CountRows(Filter(EditCollection, Or(IsBlank(D), IsBlank(E), IsBlank(F)))
) > 0 ,
Notify("Admin Role is required", Error),
SubmitForm(Form)
)
@indhaa ,
Problem with free-typing code on a Sunday - that syntax should be invalid as it is missing two brackets - I have fixed it on the original post
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.
Hi,
Hope you are available
So I added as below. Even if the Edit collections is not Empty it is not submitting the form when the NEW collection is empty. I tested by keeping only the Edit Collection and it submit in that case.
So I tried by changing by putting the Edit Collection first and then the New but still it doesn't work. Only if New Collection is not empty it is submitting. I don't know why since I cant see any issue with the code.
Pls Let me know what I'm missing
If(
CountRows(
Filter(
NewCollection,
IsBlank(A) || IsBlank(B) || IsBlank(C)
) > 0 ||
CountRows(
Filter(
EditCollection,
IsBlank(D) || IsBlank(E) || IsBlank(F)
) > 0,
Notify(
"Admin Role is required",
Error
),
SubmitForm(Form)
)
Yah, I assumed @RandyHayes was asleep that's why I tag you since I get response from you at this time and was hoping you will respond even if it is Sunday.
I was hoping to live the app today, sorry for disturbing on a Sunday. I will check this out
@indhaa ,
You we missing the >0 argument on the first part.
BTW @RandyHayes is probably asleep right now - we can only respond as time zone allows.
If(
CountRows(
Filter(
NewCollection,
IsBlank(A) || IsBlank(B) || IsBlank(C)
)
) > 0 ||
CountRows(
Filter(
EditCollection,
IsBlank(D) || IsBlank(E) || IsBlank(F)
)
) > 0,
Notify(
"Admin Role is required",
Error
),
SubmitForm(Form)
)
Please also take some time to understand the logic when you get a solution - it will help you greatly for the future.
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