cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Tim10
Regular Visitor

How to populate a form's choice from a previous form submission

Hello

 

I have 2 lists in Sharepoint: 

BasicInfo (ID, Name, CompanyName)

COVIDResponse (basicInfoID, Question1, Question2, Question(n+1) ..)

 

I have set COVIDResponse.basicInfoID to be a Lookup against BasicInfo, and set this as a required field.  On the sharepoint end of things, this works great - I must enter the data in BasicInfo first, then I am able to create a row in COVIDResponse - first selecting the correct basicInfo record before being able to create the COVIDResponse record.

 

I am trying to make a Powerapp for my users to use.  I've created the BasicInfo form without issue - data submits, etc.

 

On the next screen, I want to present the COVIDResponse fields.  Since I've made COVIDResponse.basicInfoID required, I need to know how to set it from the BasicInfo submission.

 

I have tried following https://wonderlaura.com/2017/08/16/powerapps-set-sharepoint-lookup-field/, but she's pre-populating (and pre-selecting) a field in a select list.  This method didn't seem to work in my application.

 

I have tried using the Lookup() function (following loosely on https://powerusers.microsoft.com/t5/Building-Power-Apps/Auto-populate-fields-based-on-the-users-inpu...) by settings the Items value to "LookUp('Basic Visitor Information', ID=BasicVisitor_Form.LastSubmit.ID)", but this resulted in an error - Items is looking for a Table value, and lookup returns a single record.

 

Help? 🙂

 

Thanks,

 

Tim

1 ACCEPTED SOLUTION

Accepted Solutions
Tim10
Regular Visitor

I don't get a choice as to the field type when I add the field - I am adding a field from a data source, and it comes in predefined as complex.

 

I found a thread at https://powerusers.microsoft.com/t5/Building-Power-Apps/Set-Default-Value-for-Lookup-Field-in-New-Fo... describing the exact problem I am having, and applied the solution there.  Seems to work so far!

 

Thank you again for your help with this, and apologies for not being clear on the exact issue I was encountering.

View solution in original post

12 REPLIES 12
eka24
Super User III
Super User III

Do you want to have the previous submitted on your form.

 

On the Onsuccess of the form put;

Set(varLastsubmit,FormName.LastSubmit)

 

Then on the forms ITEM put:

varLastsubmit

 

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Tim10
Regular Visitor

That generates an error "Expected a value compatible with DataSource".

 

I think I know how to access previous form data.  I don't know how to populate a Lookup field with data from a submission to another form.

 

If this were SQL, I would be thinking about how to set the "basicInfoID" to be the submission ID - but I'm not sure sharepoint works that way.

eka24
Super User III
Super User III

Maybe what you want to achieve is not clear enough. Do you want to populate a field based on the last Submit ID

 

Can you give example

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Tim10
Regular Visitor

 

Could be..  I'll post some screens from the actual app..

 

This is "Basic Information" form - collecting a visitors name, company and their contact person.  This form is tied to a Sharepoint list.

firstform.png

 

This is the "COVIDResponse" form.  This collects personal information and some screening questions we're asking for visitors.  This is also tied to a Sharepoint list.

secondform.png

 

I would like to pre-populate "BasicVisitorID" with a reference of some sort to the first form's submission, so the user doesn't have to select it.  If I can get this to work, I would then hide the BasicVisitorID card.

 

Does this help illustrate what I'm trying to do?

 

Thanks for your help,

 

Tim

 

 
eka24
Super User III
Super User III

My observation

1. Your first form doesn't indicate any ID to populate the visitor ID in the second form

2. To populate the dropdown with visitor ID, will depend on the ITEMS of the dropdown. What formula is in the dropdown.

3. An alternative is to just insert a Textbox and put; BasicVisitor_Form.LastSubmit.ID

Instead of dropdown if that would be ok.

 

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Tim10
Regular Visitor

Hi

 

I was hoping to use the Sharepoint ID that is generated when a record is added to the sharepoint list.

 

The dropdown is defined as Choices([@'Private Visitor Information'].BasicVisitorID), and gives a list of numbers (that correspond to the rows in BasicInfo)

 

Since BasicVisitorID is associated with a field in another Sharepoint list, can I just replace it with a text field with the ID?  Or does that break the .. "relationship" between the data rows?

 

Thanks again for your help.

 

eka24
Super User III
Super User III

Based on the Items property of the dropdown you have shown, try these options:

1. On Default of the dropdown

     varLastsubmit.ID

That's Onsuccess of the form create a variable; Set(varLastsubmit, FormName.LastSubmit)

 

Or

2. Just insert a Textbox instead of the dropdown and put: varLastsubmit

The relationship will not affect the variable

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

 

Tim10
Regular Visitor

Hi, thanks again for your ongoing help!

 

1. Setting the default, I get an error in the editor:  Expected Record Value. The property on this control expects Record values. The rule produces Number values which are incompatible.

 

2. I removed the dropdown from the field list, added a textbox, and set "varLastSubmit" as the Default value.  I got an error "Expected Text value. The property on this control expect Text values. The rle prdocues Record values which are incompatible.".

 

I tried to set the default value to be varLastSubmit.ID (which actually generated an output in the textbox), but received this error when submitting the form: BasicVisitorID: Field "BasicVisitorID" is required.

 

I set the data field of the card to "BasicVisitorID", but received the same output.

 

Thank you again for your ongoing help. 

 

 

eka24
Super User III
Super User III

On the second point 2. 

"this error when submitting the form: BasicVisitorID: Field "BasicVisitorID" is required"

 

Am some how not clear. We are talking about 2 forms. On with the last Submit formula and the other picking the variable Last submit from the first form.

 

Which form complains of the required field. 

 

Also I suggest you remove the datacard as you suggested and insert a new one which contains the Datacarvalue. Then put the variable varLastSubmit.ID . Please not just a Textbox.

 

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (2,745)