CASE: reference templates across each other (cross references)

Let’s say we overview done calculations in recon template A, where the calculations are done in another recon template B. Then it’s a good idea to reference those templates to each other:

  • in recon A we’ll implement a link to recon B (so it’s clear where the values are coming from);
  • in recon B we’ll implement an info-text explaining that the calculated values will be used somewhere else, with a link to the recon A

This is cross-referencing, where in A we link to B and in B we link to A. As we’ve seen in this case, don’t we need to be aware of circular references?

Summary

CASE reference values across templates by using result tags

Actually, not at all. Implementing links (linkto-tags) is calling on database variables (so data that exists on database level), which means you can do that from everywhere. It would be different if you’d work with result-tags: those are actually local variables (data that does not exist on data level, but are loaded when opening the working papers). It’s only in the last case, things would be programmed differently.

Let’s see how we can implement this for recon A, called TAX 1 (with handle tax_1) and recon B, called TAX CALC 20 (with handle tax_calc_20):

In recon A we’ll have this:

{% comment %}take values from TAX CALC 20{% endcomment %}

{% comment %}when TAX CALC 20 is unstarred, no need to show anything at all. If it doesn't exist, the same, but create an warning text instead{% endcomment %}
{% assign tax_calc_20 = period.reconciliations.tax_calc_20 %}
{% if tax_calc_20 != blank and tax_calc_20.starred? == true %}
  {% assign show_calc_20 = true %}
  {% assign calc_20 = tax_calc_20.results.calc_20 %}
  {% assign calc_20_name = tax_calc_20.name %}
  {% capture linkto_calc_20 %}{% linkto tax_calc_20 %}{{ calc_20_name }}{% endlinkto %}{% endcapture %}
{% endif %}


{% assign year = period.year_end_date | date:"%Y" %}


{% stripnewlines %}
|----40%----
|----20%----
|----20%----
|----20%----:+
{% newline %}
|
| Link
| _{{ year }}_
|
{% if show_calc_20 %}
  {% newline %}
  | Calc 20
  | {{ linkto_calc_20 }}
  | {{ calc_20 | currency }}
  |
{% endif %}
{% endstripnewlines %} 

Preview:

In recon B we’ll create this:

{% comment %}percentage for each fiscal year{% endcomment %}
{% assign fy = period.fiscal_year %}
{% case fy %}
{% when 2017 %}
  {% assign perc = 0.17 %}
{% when 2018 %}
  {% assign perc = 0.25 %}
{% else %}
  {% assign perc = 0.25 %}
{% endcase %}

{% assign print_perc = perc*100 | remove:".00" %}

{% comment %}create value of selected ranges{% endcomment %}
{% assign prov_range = custom.range.tax_prov %}
{% assign prov_value = period.accounts | range:prov_range %}

{% comment %}create warning if no accounts are selected!{% endcomment %}
{% if prov_value == empty %}
  {% assign check_range = 1 %}
{% else %}
  {% assign check_range = 0 %}
{% endif %}
{% unreconciled check_range %}

{% comment %}create var to linkto referenced template{% endcomment %}
{% assign tax_1 = period.reconciliations.tax_1 %}
{% if tax_1 != blank %}
  {% linkto tax_1 %}{{ tax_1.name }}{% endlinkto %}
{% else %}
  {% ic %}
    {::warningtext as="hover"}
    Make sure template "TAX 1" is added to the working papers
    {:/warningtext}
  {% endic %}
{% endif %}

<br>


{% ic %}
{% if check_range != 0 %}{::warningtext}{% else %}{::infotext}{% endif %}
Select accounts with values {% input custom.range.tax_prov as:account_collection range:"6" %}
{% if check_range != 0 %}{:/warningtext}{% else %}{:/infotext}{% endif %}
{% endic %}

<br>

{% stripnewlines %}
| Calculation
|
{% newline %}
|----80%----
|----20%----#
{% newline %}
| {{ prov_value | currency }} x {{ print_perc | integer }}% =
| {{ prov_value*perc | currency }}
  {% assign calc_20 = prov_value*perc %}
{% endstripnewlines %}

{% result 'calc_20' calc_20 %}

Preview:

This is a pretty basic set-up, but let’s dive into it.

For recon B:

{% comment %}create var to linkto referenced template{% endcomment %}
{% assign tax_1 = period.reconciliations.tax_1 %}
{% if tax_1 != blank %}
  {% linkto tax_1 %}{{ tax_1.name }}{% endlinkto %}
{% else %}
  {% ic %}
    {::warningtext as="hover"}
    Make sure template "TAX 1" is added to the working papers
    {:/warningtext}
  {% endic %}
{% endif %}

First of all, we’ll create a local var called tax_1 which is actually our recon template TAX 1:

{% assign tax_1 = period.reconciliations.tax_1 %}

However, always check if the referenced template is added to the working paper or not, which we’ll do with this part of code:

{% if tax_1 != blank %}
{% linkto tax_1 %}{{ tax_1.name }}{% endlinkto %}
{% else %}
{% ic %}
{::warningtext as=“hover”}
Make sure template “TAX 1” is added to the working papers
{:/warningtext}
{% endic %}
{% endif %}

If TAX 1 does indeed exist, I can call upon the name of that template with {{ tax_1.name }}.
If I want the name to be used as a link as well, I can use the linkto-tag:

{% linkto tax_1 %}{{ tax_1.name }}{% endlinkto %}

where the local var tax_1 is used to link to the right recon template.

If the recon template TAX 1 does not exist (so if tax_1 is not blank), we’ll implement a warning-tag:

{% ic %}
{::warningtext as=“hover”}
Make sure template “TAX 1” is added to the working papers
{:/warningtext}
{% endic %}

The value of our calculation (that has to be displayed in recon A), is taken into a result-tag so I can use that result-tag later on in recon A:

{% result ‘calc_20’ calc_20 %}

We’ve done now everything for recon B. Let’s take a look for recon A, where we have this:

{% comment %}when TAX CALC 20 is unstarred, no need to show anything at all. If it doesn't exist, the same, but create an warning text instead{% endcomment %}
{% assign tax_calc_20 = period.reconciliations.tax_calc_20 %}
{% if tax_calc_20 != blank and tax_calc_20.starred? == true %}
  {% assign show_calc_20 = true %}
  {% assign calc_20 = tax_calc_20.results.calc_20 %}
  {% assign calc_20_name = tax_calc_20.name %}
  {% capture linkto_calc_20 %}{% linkto tax_calc_20 %}{{ calc_20_name }}{% endlinkto %}{% endcapture %}
{% endif %}

First, we create a local var to direct us to the recon B, like this:

{% assign tax_calc_20 = period.reconciliations.tax_calc_20 %}

The, we decide on whether or not if recon B exists AND if it is starred as well. So we need to check if the local var tax_calc_20 is different from blank AND we check if the method starred? gives us the value true (meaning the template is starred) or false (if it isn’t starred):

{% if tax_calc_20 != blank and tax_calc_20.starred? == true %}

When those 2 conditions are true, we’ll create a local var show_calc_20 and assign it to the value true

{% assign show_calc_20 = true %}

This will be used to display the results from recon B or not.

We’ll assign the result-tag from recon B as well:

{% assign calc_20 = tax_calc_20.results.calc_20 %}

and we’ll assign the name of recon B into a local var as well:

{% assign calc_20_name = tax_calc_20.name %}

We’ll create a linkto as well, and capture it for later use in the code:

{% capture linkto_calc_20 %}{% linkto tax_calc_20 %}{{ calc_20_name }}{% endlinkto %}{% endcapture %}

If the recon B does actually exists and is starred, we’ll print the needed info in our table:

{% if show_calc_20 %}
  {% newline %}
  | Calc 20
  | {{ linkto_calc_20 }}
  | {{ calc_20 | currency }}
  |
{% endif %} 

This case has no interference with circular references. However, it would be quite different if recon B needed a local var (like a result-tag) from recon A (because recon A is already looking at the local var from recon B).

When you start with references from templates across each other, be sure that from the start it’s clear what you want to reference with.
If there are a lot of results to be linked to (local vars), it might become a situation where you need to re-create your code, and calculate a result again from scratch to avoid circular references.
If it’s just a link that is used as a reference, then there’s no harm (because it’s database variables you refer to).

This can become quite challenging, which is why we advise you to make up a blueprint from scratch, if you start building templates with cross-references in it.