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.
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 Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (1,824)