cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
ggeorge
Level: Powered On

ClearCollect returning the wrong ID

I have an app with 2 forms. 

Form 1 - Sends Business Case information to SQL on-premise

Form 2 - I need to retrieve the ID SQL has generated for the last record. (As one business case can have many suppliers.)

 

On the submit button of form 1 I have the following:

ClearCollect(NewThreeQuote, Patch('[dbo].[tblFrameworkJobs]',Defaults('[dbo].[tblFrameworkJobs]'),{SubCaseTitle: TextInput2_1.Text,DescriptionOfWorks: TextInput2.Text, EstimatedCost:Value(TextInput2_2.Text), RequiredEndDateSmiley Very HappyatePicker1_1.SelectedDate, RequiredStartDateSmiley Very HappyatePicker1.SelectedDate,HSComments:TextInput2_3.Text, LeadOfficer:ComboBox2.Selected.ID, PurchaseType:ComboBox3.Selected.ID, Category:ComboBox4.Selected.CategoryID, BusinessUnit:ComboBox2_1.Selected.BusinessUnitID, Director:ComboBox5.Selected.ID,HSLead:ComboBox6.Selected.ID,ContractRegisterID:ComboBox1.Selected.ProjectTeamID}) );Navigate(Screen2,ScreenTransition.Fade)

 

OnVisible of Screen 2 I have the following:

Collect(NewThreeQuote, '[dbo].[tblFrameworkJobs]')

 

I have set the default of TextInput3 to Last(NewThreeQuote).SubCaseID 

 

Then on submit of Form 2:

ForAll(
RenameColumns(RenameColumns(RenameColumns(RenameColumns(
RenameColumns(UploadData,"CompanyID","CompanyID1"),
"FrameworkJobID","FrameworkJobID1"),"Price","Price1"),"WinningBid","WinningBid1"),"Notes","Notes1"
),
Patch('[dbo].[tblFrameworkJobTenders]',Defaults('[dbo].[tblFrameworkJobTenders]'),{FrameworkJobID:Value(FrameworkJobID1),CompanyID:CompanyID1,Price:Value(Price1),WinningBid:WinningBid1,Notes:Notes1})
);
Navigate(Screen3,Fade)

 

If I create a record and submit, it sends information across to SQL. However, it is not returning the correct ID (Foriegn key on the second form). 

 

Apologies if i'm not making sense i'm new to PowerApps. It adds the business case fine, but on form two it seems to retrieve the business case ID of the one before the one just submitted if that makes sense.

 

Any help will be gratefully appreciated.

 

Thank you in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Mike8
Level 10

Re: ClearCollect returning the wrong ID

Hello ggeorge,

I think it needs time. You can test if this is the case, by removing the Navigate(Screen2,ScreenTransition.Fade) from the submit button of form 1, have it separate on an other button (Button1) and press Button1 a few seconds after you submit form 1.

 


Tip.. you can try to check if it works the same if you change the expression on submit of Form 2 to: 
ForAll(
UploadData,
Patch('[dbo].[tblFrameworkJobTenders]',Defaults('[dbo].[tblFrameworkJobTenders]'),{FrameworkJobID:Value(UploadData[@FrameworkJobID]),CompanyID:UploadData[@CompanyID],Price:Value(UploadData[@Price]),WinningBid:UploadData[@WinningBid],Notes:UploadData[@Notes]})
);
Navigate(Screen3,Fade)

View solution in original post

2 REPLIES 2
Mike8
Level 10

Re: ClearCollect returning the wrong ID

Hello ggeorge,

I think it needs time. You can test if this is the case, by removing the Navigate(Screen2,ScreenTransition.Fade) from the submit button of form 1, have it separate on an other button (Button1) and press Button1 a few seconds after you submit form 1.

 


Tip.. you can try to check if it works the same if you change the expression on submit of Form 2 to: 
ForAll(
UploadData,
Patch('[dbo].[tblFrameworkJobTenders]',Defaults('[dbo].[tblFrameworkJobTenders]'),{FrameworkJobID:Value(UploadData[@FrameworkJobID]),CompanyID:UploadData[@CompanyID],Price:Value(UploadData[@Price]),WinningBid:UploadData[@WinningBid],Notes:UploadData[@Notes]})
);
Navigate(Screen3,Fade)

View solution in original post

ggeorge
Level: Powered On

Re: ClearCollect returning the wrong ID

Thank you very much Mike, that code worked a treat!

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

Top Kudoed Authors
Users Online
Currently online: 371 members 4,511 guests
Please welcome our newest community members: