cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DAVIDPOWELL
Impactful Individual
Impactful Individual

Create a new master record and detail record from button click

The following code below will create a Master record.

What I need:

I need to create a "detail" record using the ID created in the patch statement below.(from master)  
The detail table is called "t_pricing_escalation_detail"

The foreign field is  "RBP_MASTER_ID"  

 

 

Set(MyRecord,
Patch(t_pricing_escalation_master,Defaults(t_pricing_escalation_master),
{
ESCALATION_CREATED_BY: User().FullName,
QS_RACFID: txt_QS_RACFID.Text
}
)
)

 

Thanks

Dave

4 REPLIES 4
RandyHayes
Super User
Super User

@DAVIDPOWELL 

You're storing the patch results in your MyRecord variable. This will have all of the information you need for you other patch. 

Patch(t_pricing_escalation_detail, Defaults(t_pricing_escalation_detail),
    {RBP_MASTER_ID: MyRecord.ID}
)

Will give you a new record with the master record ID in the RBP_MASTER_ID column.

 

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!

randy, getting this error ?

Both fields are INT in sql server.

error patch with id.png

Set(MyRecord,
Patch('[dbo].[t_redbook_pricing_escalation_master]',Defaults('[dbo].[t_redbook_pricing_escalation_master]'),
{

ESCALATION_CREATED_BY: User().FullName,
QS_RACFID: txt_QS_RACFID.Text


}
)
)
;
Patch('[dbo].[t_redbook_pricing_escalation_detail]', Defaults('[dbo].[t_redbook_pricing_escalation_detail]'),
{
RBP_MASTER_ID: MyRecord.PRICING_ESCALATION_ID

}
)

RandyHayes
Super User
Super User

@DAVIDPOWELL 

If you're getting a "found type error", then something else is at play.  

I would take the formula in error out for the moment and then look at the variable you are setting (MyRecord) to see what is in that column PRICING_ESCALATION_ID

_____________________________________________________________________________________
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!

This is a primary key  AUTONUMBER field.   PRICING_ESCALATION_ID

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,442)