cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
venka91
Post Partisan
Post Partisan

ForAll records in Collection, check the share point list item exists

Hi there,

 

My scenario as below.

I have a collection by name Templist. This collection will have a data from a share point list.-1.

I have a Share point list-2 on which i would like to see, the items on my share point list-1 already exists or not. I have written the code as below. But does not seem to work. how to check this ?

 

OnSelect of Filter Icon: 

ClearCollect(TempList, Filter(SP1, campus.Value = ddcampus.Selected.Value && class.Value = ddclass.Selected.Value));

 

OnSelect of Button:

ForAll(TempList,
If(
CountRows(Filter(SP2, student_name = Name && class = ddclass.selected.value && campus = ddcampus.selected.value)) > 0,

Notify("Record Exists"),
Notify("Record does not exists");
Patch(SP2, Defaults(SP2),{student_name:student_name},{class:class.Value},{campus: campus.Value}, Attendance_date:adate_home.SelectedDate})));

 

If the record does not exists in SP2, i would like to patch the collection items to SP2. if the collection item records, and SP2 record item are same, it should not be patched and should popup a message, record already exists.

1 ACCEPTED SOLUTION

Accepted Solutions

@venka91 ,

I am sorry to keep repeating this, but one pop-up will replace another throughout the loop and in the end you will only see the last one and not know which item it applies to. If you want to see a list of items from the collection not in the list

With(
   {
      wList1:
      Filter(
         SP1,
         campus.Value = ddcampus.Selected.Value && 
         class.Value = ddclass.Selected.Value
      ),
      wList2:
      Filter(
         SP2,
         campus = ddcampus.Selected.Value && 
         class = ddclass.Selected.Value
      )
   },
   Filter(
      wList1,
      !(ID in wList2.ID)
   )
)

 

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.

Visit my blog Practical Power Apps

View solution in original post

21 REPLIES 21
WarrenBelz
Super User
Super User

Hi @venka91 ,

Firstly, forget about the Notify() items in the middle of the ForAll - you will not see then quick enough. YOu also might try doing it all together

With(
   {
      wTemp:
      Filter(
         SP1,
         campus.Value = ddcampus.Selected.Value && 
         class.Value = ddclass.Selected.Value
      )
   },
   ForAll(
      wTemp As aPatch,
      With(
         {
            wID:
            LookUp(
               SP2, 
               student_name = aPatch.student_name && 
               class = aPatch.class.Value && 
               campus = aPatch.campus.Value
            ).ID
         },
         If(
            IsBlank(wID), 
            Patch(
               SP2, 
               Defaults(SP2),
               {
                  student_name:aPatch.student_name,
                  class:aPatch.class.Value,
                  campus: aPatch.campus.Value, 
                  Attendance_date:adate_home.SelectedDate
               }
            )
         )
      )
   )
)

 

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.

Visit my blog Practical Power Apps

Thank you. But when i change the Attendance date in date picker, the new records are not getting patched into SP2. I want to patch the SP2 along with the date value that is my date picker control.

venka91
Post Partisan
Post Partisan

Sorry, I figured out where i was wrong. But only one help in validation. If the filter values, example, Class and Campus does not exists in SP1, i want to show, there is no data on the Button Onselect of the above code what you have given.

 

Could you please assist where do i add that validation ? it will be great help.

venka91
Post Partisan
Post Partisan

Could you please help me further

@venka91 ,

Which records? You are in a ForAll loop

venka91
Post Partisan
Post Partisan

with the same formula you have given, if there is no record exists in SP1, i want to populate a notify, no records exists in SP1.

@venka91 ,

Yes, but if you are running this in a ForAll loop how do you know which record the notification applies to?

venka91
Post Partisan
Post Partisan

The selection is based on SAL. In Your formula, first we are filtering records from SAL based on campus and class. If this campus and class does not exists in SAL, I want to display a popup no record exists in Master file SAL. 

 

Can you please help me how do I validate. If I give this in loop, I feel for each item in SharePoint list it will show the popup.  

 

If I go out of loop, I don't know how to I validate. 

 

So please help me in completing this validation. 

@venka91 ,

I am sorry to keep repeating this, but one pop-up will replace another throughout the loop and in the end you will only see the last one and not know which item it applies to. If you want to see a list of items from the collection not in the list

With(
   {
      wList1:
      Filter(
         SP1,
         campus.Value = ddcampus.Selected.Value && 
         class.Value = ddclass.Selected.Value
      ),
      wList2:
      Filter(
         SP2,
         campus = ddcampus.Selected.Value && 
         class = ddclass.Selected.Value
      )
   },
   Filter(
      wList1,
      !(ID in wList2.ID)
   )
)

 

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.

Visit my blog Practical Power Apps

View solution in original post

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (2,606)