cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
halifaxious
Resolver II
Resolver II

business rule to set default based on related record

I have 2 tables:

  • Questions (a list of questions I need answered)
  • Answers (a list of answer choices that the user can answer my questions with)

Each Question has zero or more related Answers.  Each Answer has a sort_order field containing a positive integer. The sort_order field defines the order in which the Answers related to a specific Question are displayed.

 

When I add a new Answer, I want to set its default sort_order to the maximum sort_order for Answers to that Question + 1.

For example, if I were adding the first Answer ever to a Question, the sort_order default would be set to 1. But if I were adding the 3rd Answer to that Question, the sort_order default would be the result of a query something like this pseudocode:

 

Select MAX(sort_order)+1 from Answers where Question=X.

 

This is for a model-driven app. Can I do it with a business rule or a calculated field? If so, how? If not, could it be done with Power Automate?

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisPiasecki
Dual Super User
Dual Super User

Hi @halifaxious,

 

You won't be able to leverage business rules since they can only set values based on columns in the immediate table, not related tables. Calculated fields can only reference the current table or parent table, not a child table.

 

You could maintain a current sort order on your Question record. Using a Dataverse real-time workflow (triggered on create of a Answer record), you can set the sort order for the Answer based on the current sort order of the Question record, then increment the current sort order on the Answer.

 

Power Automate gives you more flexibility as it can retrieve child records whereas Dataverse workflows can only work with the immediate record and parent record. The only downside is that Power Automate runs asynchronously so if you absolutely require real-time then it is not an option.

 

Other alternatives would be to use JavaScript and/or a Plugin, both requiring code. A plugin would be the most reliable way to do this asynchronously.

 

---
Please click Accept as Solution if my post answered your question. This will help others find solutions to similar questions. If you like my post and/or find it helpful, please consider giving it a Thumbs Up.

 

 

View solution in original post

1 REPLY 1
ChrisPiasecki
Dual Super User
Dual Super User

Hi @halifaxious,

 

You won't be able to leverage business rules since they can only set values based on columns in the immediate table, not related tables. Calculated fields can only reference the current table or parent table, not a child table.

 

You could maintain a current sort order on your Question record. Using a Dataverse real-time workflow (triggered on create of a Answer record), you can set the sort order for the Answer based on the current sort order of the Question record, then increment the current sort order on the Answer.

 

Power Automate gives you more flexibility as it can retrieve child records whereas Dataverse workflows can only work with the immediate record and parent record. The only downside is that Power Automate runs asynchronously so if you absolutely require real-time then it is not an option.

 

Other alternatives would be to use JavaScript and/or a Plugin, both requiring code. A plugin would be the most reliable way to do this asynchronously.

 

---
Please click Accept as Solution if my post answered your question. This will help others find solutions to similar questions. If you like my post and/or find it helpful, please consider giving it a Thumbs Up.

 

 

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Users online (3,594)