cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rprahalad
Helper I
Helper I

1-Many - How can I persist both Master and Detail records at the same time.

Hello All,

Most of the examples I have read on the web have been where the Master record already exists and we display it on a gallery and the user clicks on one of 'em  and enters and saves the "many" Detail records. But in my case I have to Save both Master and Details at the same time. Here are my tables: QM has a 1-Many relationship with QueueDetails

 

QueueMaster ->  QueueID is the PK (Autogenerated Number field)

QueueDetails  -> Contains a bunch of fields + QueueID from above.


How can I save the QueueMaster record ->Grab the QueueID of the newly inserted row -> Save the detail records with this QueueID, all in the click of a button?  Note: QueueID is an AutoGenerated number field.

Please let me know what's the best way to do this within Canvas Apps?

Thank You!

1 ACCEPTED SOLUTION

Accepted Solutions
v-siky-msft
Community Support
Community Support

Hi @rprahalad ,

 

What is the data source? SQL table or CDS entity? 

The key point of this scenario is get the record just saved from master entity.

When using Patch function to save the master entity record, use Set() as below to save the entire record to variable.

Set(varRecord, Patch('Master entity', Defaults('Master entity'), {...}))

Then if the data source is sql table, you just need to save the varRecord.QueueID to the QueueID field in QueueDetails .

If the data source is Entity, the QueueID field requires a entire record from Master entity, so save the varRecord to QueueID field.

Hope this helps.

Sik

View solution in original post

3 REPLIES 3
v-siky-msft
Community Support
Community Support

Hi @rprahalad ,

 

What is the data source? SQL table or CDS entity? 

The key point of this scenario is get the record just saved from master entity.

When using Patch function to save the master entity record, use Set() as below to save the entire record to variable.

Set(varRecord, Patch('Master entity', Defaults('Master entity'), {...}))

Then if the data source is sql table, you just need to save the varRecord.QueueID to the QueueID field in QueueDetails .

If the data source is Entity, the QueueID field requires a entire record from Master entity, so save the varRecord to QueueID field.

Hope this helps.

Sik

View solution in original post

Hi @v-siky-msft ,

 

Many Thanks for your response! Yes, that seems to work and I am using CDS. BUT I maybe doing something wrong here. When I  go to the Portal and open up the QueueDetails Entity and look at the Data tab, the QueueMasterID column, which is of type LookUp to QueueMaster table,  is showing Blank for all the QueueDetail rows. 

 

That kind of is throwing me off if it is really saving the Masters reference ID. I look at the QueueMaster entity data and indeed the record is saved even there.  How do I view the data in the Lookup field (Referenced field to Master's ID) within the CDS Portal?

 

Thanks again!

I threw in a Gallery within my Canvas app and sure enough, I am able to see the referenced QueueMaster  data as well! So, it is working as expected BUT I guess the CDS Portal does not show the referenced Data but does store the references internally somehow.   

 

Thanks and marked it as the Solution!

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!

secondImage

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (3,673)