cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DAVIDPOWELL
Post Prodigy
Post Prodigy

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.
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.
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
User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

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 (1,858)