Example custom functions

Changing other Q&A answers upon changing a specific answer

Through change sets, ClauseBase allows you to change datafields, terms, styling, etc. that apply when certain answers are given. However, it is not possible for an answer to change some other answer. Clojure functions allow you to resolve this limitation.

Suppose you are creating a contract and you want to give the user the option to pre-fill answers in a single click. For example, suppose you want to give the users the option to choose between “neutral” and “aggressive” default answers.

  1. Create a text-question with title “Which style do you want?” with identifier “style” that contains two predefined answers: “neutral” and “aggressive”. Set the “free answers?” option to “not allowed”.
  2. Create a yes/no-question “Is recourse allowed?” with identifier “recourse”.
  3. Create a currency-question “Which liability cap applies?” with identifier “cap” that contains two predefined answers (200 EUR and 5000 EUR).

Add a to the first question, and insert the following code:

(defn action-fn [q a]
  (case a
    "neutral" (do (set-answer "recourse" true)
                  (set-answer "cap" (->CurrencyValue 50000000 :EUR)))
    "aggressive" (do (set-answer "recourse" false)
                  (set-answer "cap" (->CurrencyValue 2000000 :EUR)))
    nil))

(assoc question :action-fn action-fn)

This code extends the question var (which is assigned the current question by ClauseBase upon initialization of the Clojure environment) with an action-function.

This action-function takes two arguments (the question and the answer-value). It then checks which answer was given, and sets the answer of the two other questions to the desired values.

Note that the currency-values are integers multiplied by 10000 to make room for potential decimals.

The result is as follows:

Was this article helpful?
Dislike
Custom functions