cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
halifaxious
Helper II
Helper 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
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,762)