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
Super User
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
Super User
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

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Users online (1,976)