cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Fess67
Helper I
Helper I

ForALL( Patch)) Only updates the first record

Hi,

I feel I am close to solving this one however I need help getting over the line.  I have followed the principle that Shane Young used in his video https://www.youtube.com/watch?v=0xZ4fMJbLvk, however I do not want to use a checkbox.

I have a skills matrix and an individual employee will have multiple skills recorded.  If they change position or location etc I need to be able to update all of their records in the skills matrix. It only patches the first instance of the selected employee.

The first patch is to set the IsChosen to true and then patch the main record.

 

Patch(TeamCollection,GalleryTeamList.Selected, {IsChosen:true});

ForAll(
RenameColumns(Filter(TeamCollection,IsChosen),"EmployeeNumber","EmpNum"),
Patch(SkillsMatrix,LookUp(SkillsMatrix,EmployeeNumber=EmpNum),
{
Surname: AmendSurname.Text,
FirstName: AmendFirstName.Text,
Location: AmendLocation.Text,
Position: AmendPosition.Text
}
));

ClearCollect(TeamCollection,AddColumns(TeamList,"IsChosen",false));

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Eelman
Super User
Super User

@Fess67 

Your first Patch() appears to update a column in a Collection called "IsChosen" to true for a selected Gallery item. Then, your ForAll() filters that collection based on IsChosen = true. Is this correct? If so, then your filter is only returning 1 record and that's why only 1 record gets updated.

 

I'd suggest using a variable to do what you need here, like this:

// create variable from selected Gallery item
// add this code to your Gallery.OnSelect or any icons/labels you are using to do your first Patch
Set(vEmpNum, GalleryTeamList.Selected.EmployeeNumber);

// Patch updated info

ForAll(
     // note, I assume you have a column called Skill, if not, change this to suit your field name
     RenameColumns(Filter(SkillsMatrix,EmployeeNumber=vEmpNum),"Skill","Skill_1"),
        UpdateIf(SkillsMatrix, Skill=Skill_1,
           {
           Surname: AmendSurname.Text,
           FirstName: AmendFirstName.Text,
           Location: AmendLocation.Text,
           Position: AmendPosition.Text
           }
        )
);

As I say, I assume you have a column called "Skill" and also that when you select a Gallery item you can access the EmployeeNumber that you need to reference. If this isn't correct, then you'll need to adjust your code to suit.

 

I think that should do it? 

View solution in original post

4 REPLIES 4
Eelman
Super User
Super User

@Fess67 

Your first Patch() appears to update a column in a Collection called "IsChosen" to true for a selected Gallery item. Then, your ForAll() filters that collection based on IsChosen = true. Is this correct? If so, then your filter is only returning 1 record and that's why only 1 record gets updated.

 

I'd suggest using a variable to do what you need here, like this:

// create variable from selected Gallery item
// add this code to your Gallery.OnSelect or any icons/labels you are using to do your first Patch
Set(vEmpNum, GalleryTeamList.Selected.EmployeeNumber);

// Patch updated info

ForAll(
     // note, I assume you have a column called Skill, if not, change this to suit your field name
     RenameColumns(Filter(SkillsMatrix,EmployeeNumber=vEmpNum),"Skill","Skill_1"),
        UpdateIf(SkillsMatrix, Skill=Skill_1,
           {
           Surname: AmendSurname.Text,
           FirstName: AmendFirstName.Text,
           Location: AmendLocation.Text,
           Position: AmendPosition.Text
           }
        )
);

As I say, I assume you have a column called "Skill" and also that when you select a Gallery item you can access the EmployeeNumber that you need to reference. If this isn't correct, then you'll need to adjust your code to suit.

 

I think that should do it? 

View solution in original post

Thanks for that, @Eelman 

I changed the code slightly as I was trying to have the EmployeeNumber as the constant and I can now change any other attribute about the individual and have it update all records in the matrix.

 

I have a question about updateif.  I was avoiding that and trying to use patch as I though the updateif would run into delegation issues.  Is this going to fall over as soon as I add a decent number of records?

@Fess67 

Yes unfortunately, UpdateIf will eventually run into delegation issues but it may not affect your process if you are filtering the Skills of just one Employee? Surely an employee would need >2000 skills?

 

However, if you end up updating more than just one employee there's a chance your function will be affected. Spend some time on future planning your data and functions and then use that to guide you on which way to go with it.

Yes for this function I will only ever update 1 employee at a time and no, it is not likely that any employee will have more than 2000 'skills' although that is going to be something I have to manage with my managers as they think that passing a site induction is a 'skill' that needs to be recorded.

Thanks for your help, much appreciated.  

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (58,947)