Automate Recipe: Calculate Fact Fields

 

This recipe will calculate a new fact field from two (or more) existing facts. This specific recipe guide will calculate an Expiration Date from a Term(months) and Effective Date.

 

What you'll need:

Time Required: 20 minutes

Skill Level: Intermediate

  • Permission to edit facts in your ThoughtTrace Workspace

 

Create a new Recipe:

  1. Navigate to ThoughtTrace Automate and select 'Create Recipe'
    mceclip1.png

  2. Name the Recipe, select the Location (it should default to the project that was open), and select 'Trigger from an app'. Then click 'Start Building'

Build a Recipe:

  1. Select 'ThoughtTrace - User' as the app for the Trigger step. Select an existing connection, or select Create Connection. Enter in the same credentials that are used to sign into the ThoughtTrace Platform.
  2. For the Change Type field, select 'Fact Created', 'Fact Field Added', and 'Fact Field Changed'. For Fact Values, select the 2 Facts that are going to be used for the calculation. For this recipe, Term(Months) and Effective Date. This ensures the recipe will only trigger when one of the 2 fields needed for the calculation are changed or added.
    mceclip0.png
  3. Add a new action and select 'ThoughtTrace - User' as the app. Choose 'List Facts' as the action.
  4. Add the Document ID Data Pill from the Trigger action to the Document ID field. For Facts, select the 2 facts needed to calculate (in this case, Term and Effective Date) and the fact where the calculation will be added(for this example, Expiration Date).
    mceclip1.png
  5. Add a new action and select 'IF Condition'
  6. For Data Field, add 'Term' and for the Condition, select 'is present'. 
  7. Select the '+' icon to add another condition and select 'AND'. For the Data Field, enter 'Effective Date' and for the Condition select, 'is present'. This step ensures that all of the necessary fields for the calculation are present. If the necessary fields are not present, the recipe will end.
    mceclip2.png
  8. Add a new action and select the 'IF Else' action.
  9. For the condition of Line 4: set Data field to Expiration Date and Condition to 'is not present'. This will check to see if the 'Expiration Date' fact exists or not. If it does not exist, the recipe will add a new fact. If it does exist, the recipe will remove the old fact and add a new one.
  10. Follow the 'Yes' path and add an action using the 'ThoughtTrace - User' app and 'Add facts' as the action.
  11. For the Document ID field, add the Document ID Data Pill from the Trigger action. For Facts, select 'Expiration Date' (or whatever fact you would like to add)
  12. In the Expiration Date field, toggle the field to use a 'formula'
    mceclip3.png
  13. In the formula, Term and Effective Date need to be added together. Select the data pill for Effective Date from the output of action #2
    mceclip7.png
  14. Then add a plus sign (+) and select the Term from the output of action #2. For the formula to work, there are some things that have to be done to the Term value in this case. It needs to be declared as a number and also tell TT Automate that it is measured in months. Add ".to_i.months" after the term Data Pill. It should look similar to the screenshot below:

    mceclip5.png
  15. Next, below the 'ELSE' block (should be on line 6) add a new action (Line 7). Use 'ThoughtTrace - User' as the app and select 'Delete Facts' as the action.
  16. In the Document ID field, add the Document ID Data Pill from the Trigger action, and in Facts, select Expiration Date. This will delete any Expiration Date facts on this document. 
  17. Go to the previous 'Add Facts' action, right-click, and select 'Copy'
  18. Hover below the 'Delete facts' action and select 'Paste'
    mceclip6.png

 

That's it! Run some tests on your recipe to ensure it delivers the desired results. 

NOTE: When this is turned on, it will listen and take action on any documents you have access to. If you need to limit what documents this will take action on, additional rules can be added to the Trigger to be more selective or more conditions added to Line 3 to stop the recipe. 

 

Optional Enhancements

  • Update a status or workflow fact when this is successful
  • Send another notification if the expiration date is within a certain number of days/months

 

Please reach out to support@thoughttrace.com with any questions or assistance needed. Thank you!

Was this article helpful?
0 out of 0 found this helpful