Question
Declare expression (Forward and backward chaining) question
I have been preparing for Pega CSA exam and have been studying from online course on Pega training pages, I am very much confused on the forward and backward chaining concept and cant answer the below question correctly, can some one explain plz.
Question below
You have created a series of forms for a vacation booking process. Declarative expressions are used to calculate values such as the cost of the flight, hotel, car
rental, and taxes. The last form includes a field that displays the total amount that will be charged on the user’s credit card.
How do you configure the calculations so that the total amount is calculated only when the user reaches the last form?
A. Use the backward chaining option for all the expressions.
B. Use the backward chaining option for the total amount expression. Use forward chaining for all the other expressions.
C. Use the forward chaining option for all the expressions.
D. Use the forward chaining option for the total amount expression. Use backward chaining for all the other expressions.
The answer is B. Backward chaining works from the goal to its inputs. So when you get to the last page that has the total-amount field, use backward chaining to compute its value at that time and not before.
On the other hand, forward chaining works from the inputs to the goal. Thus, every time an input value changes, the forward chaining rules will fire. The question wants you to calculate the price of the individual parts of a trip like the hotel and flight as you work through the flow. Thus, use forward chaining.
If you had used forward chaining on the total amount field, it would be recomputed every time the inputs were changed by the user. That is not what the question wanted to happen.
I hope that makes sense.