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.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
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.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

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

Thank you it works!
Have a nice day!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,598)