cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Shadox
Frequent Visitor

Adding a Record with the Collect function

Hello !

 

I'm still discovering Power Apps and here I am facing a problem ...

 

I am using the Collect function to create a new line in my SharePoint list when a button is pressed. In this Collect, I fill in 2 fields:
    - StepName: "TestTemplate
    - FK_ProjectId: LastId

 

StepName is of type Text.
FK_ProjectId is a reference to another SharePoint list and it expects a Record.

 

I also create a LastId variable which corresponds to a Record (the one that will be used to fill FK_ProjectId)

Collect (
   ProjectSteps;
   {
      StepName: "TestTemplate";
      FK_ProjectId: LastId
   }
)

 

Result?
Creating an entry in my SharePoint ProjectSteps list with as StepName "TestTemplate" (normal) but the column FK_ProjectId remains empty ...

 

Why ?

I absolutely can not find it and I leave it to you!

 

The final goal?

I have a model table containing steps (step 1, step 2, step 3 ...) and I will like to create new lines in my project table (ProjectSteps) of the form ProjectId + step 1, ProjectId + step 2 , ProjectId + step 3 ...

 

Thank you 😉

 

PS : my last screen https://imgur.com/a/Ao2cRYx 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@Shadox 

When you are trying to set a Lookup column in your list, you need to provide it with a record with the Id and Value of the item you are looking up.

 

I would consider the following formula to replace your current:

With({_lastRecord:
    Patch(ProjectSummary; Defaults(ProjectSummary);
        {'Project Manager': User().FullName}
    )
    };;

    Collect(ProjectSteps;
        {StepName: "TestTemplate";
         FK_ProjectId : {Id: _lastRecord.ID; Value: _lastRecord.'Project Manager'}
        }
    )
)

This will reduce the variables and will provide what you need.

Also, the assumption in the above is that your Lookup column in SharePoint was defined to lookup to the ProjectSummary list and link to the Project Manager column.  If not, adjust accordingly.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

2 REPLIES 2
RandyHayes
Super User
Super User

@Shadox 

When you are trying to set a Lookup column in your list, you need to provide it with a record with the Id and Value of the item you are looking up.

 

I would consider the following formula to replace your current:

With({_lastRecord:
    Patch(ProjectSummary; Defaults(ProjectSummary);
        {'Project Manager': User().FullName}
    )
    };;

    Collect(ProjectSteps;
        {StepName: "TestTemplate";
         FK_ProjectId : {Id: _lastRecord.ID; Value: _lastRecord.'Project Manager'}
        }
    )
)

This will reduce the variables and will provide what you need.

Also, the assumption in the above is that your Lookup column in SharePoint was defined to lookup to the ProjectSummary list and link to the Project Manager column.  If not, adjust accordingly.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

Shadox
Frequent Visitor

Thank you it works!
Have a nice day!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Power Apps Community Call Jan. 2022 768x460.png

Power Apps Community Call

Please join us on Wednesday, January 19th, at 8a PDT. Come and learn from our amazing speakers!

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 (3,215)