CONTRACT Butler conditional logic is applied during the contract creation process. For this purpose, clause tags with simple or complex expressions can be used in custom contract creation flow.
Tag is a label or keyword that describes the content of a clause and can be used for logical operations. The tag is not unique within the template and can be applied to multiple clauses.
Example: #
Create a Template or make use of any existing template to add tags for the clauses. Let’s create a template on opportunity object and add multiple clauses. Let’s hide the each clause based on Opportunity’s Lead Source. The next steps explain how to set up conditions for the clauses, so that the system hides each clause based on the opportunity lead source value..
Create a Template #
Create below template with multiple clauses and add Tags for each clause as shown below. Follow next steps on how to add tags.
How to set up clause conditions #
In order to set up conditions in your contract, follow these steps:
Clause Tags #
First, add tags to the clauses in the template. After adding tags, they will be shown below the clause text. To do this, hover over the space below the clause text in the Template Builder and click on the tag icon as shown below.
A modal window will open as shown below, allowing you to add or edit tags for the target clause.
Filtering Subflow: Filter Agreement Placeholders #
Next, set up conditions in a Flow. This example describes a subflow with conditional clause logic based on Opportunity object field values. The subflow creates a list of clause IDs and passes it as a parameter to the ‘Create Agreement’ Flow Action in the ‘Create Agreement From Opportunity’ flow. This flow is part of the Contract Butler Starter Pack. You can install Contract Butler starter pack here.
Create a screen flow as below and call it as “Filter Agreement Placeholders”. A detailed explanation of how to build this flow is provided in the next steps.
Input parameters: #
Create below two input parameters. Pass the values to these parameters from “Create Agreement From Opportunity” flow of starter pack.
opportunity (Record) – source object record,
templateId (Text) – id of the target template.
Output parameters: #
Create below output parameter.
tagIdsToExcludeResult (Text Collection) – list of clause ids to exclude from the newly created contract.
Get template items #
At the beginning we need to retrieve all required data, for example in this case Opportunity (input parameter) and Template’s Clauses.
Get Template Items – get list of clauses by Template Id. Contract Instance Item is the object which stores the clauses of a template. So, query Contract Instance Item object records based on cadmus_contract__ContractInstance__c(Agreement template) Id as shown below.
Conditional Logic #
For conditional logic, we need tag, clause name or text. This part of the flow includes:
- Loop Items – iterate through a list of template’s clauses.
- Items to exclude Decision element – It evaluates a set of conditions based on the clause tag and the state of fields in the target record to determine which clause IDs to add to the exclusion list.
- Items to Exclude Assignment element – add the clause ID to the exclusion list
Loop through template items queried from previous step and add decision element to exclude clause ids based on the logic. In this example, I want to hide the clause where the corresponding tag contains the Opportunity record’s Lead Source value. So Create an Outcome under decision element and add the logic as shown below.
In that Outcome path, add Assignment element as shown below to exclude tag Ids or template items(Clauses) which falls under above mentioned condition.
Save the flow and activate it.
Create Agreement From Opportunity Flow #
This flow is part of contract butler starter pack. Install the starter pack from here to make use of this flow.
Flow Action: Filter Agreement placeholders #
Before the ‘Create Agreement’ flow action, we need to check whether the system should exclude any clauses from the Agreement/Contract. So add the sub flow element “Filter Agreement placeholders” before the flow action.
Set the Input and output parameters of the sub flow as shown below.
Flow Action: Create Agreement #
The following fields are crucial for evaluating the conditional clause logic in the contract generation process, and you should assign them to the ‘Create Agreement Flow’ action, as shown in the screenshot below.
templateId – used to retrieve the correct template, including its structure and associated clauses.
itemIdsToExclude – defines the specific template clauses that the system should exclude from the newly created contract.
Testing #
Open any opportunity and click on Create Agreement button(This button is part of starter pack). Give the template name and create an agreement.
Since the Opportunity’s Lead Source is ‘Purchased List’ and we haven’t excluded any clauses for this Lead Source, the system includes all clauses in the Agreement/Contract, as shown below.
Now update the opportunity’s Lead Source to “Web”.
Create an agreement, and the agreement/contract will not have the clause text with “Web” as a tag.