Check if result exists in previous period

Hi!
We have a reconciliation that shows values from the current and previous period. The reconciliation is based on a for…loop that runs through all reconciliations and results in an array. As some reconciliations have been changed we sometimes get an error where the result that is pulled does not exist. To avoid this I would like to use something similar to the method explained here: https://community.silverfin.com/t/case-check-if-another-reconciliation-exists-with-the-exists-method/1827

I have tried to adapt that example to instead check if a specific result exist but cannot get it to work. Is there a way to achieve this? The code that throws an error is like this:

{% assign sub_result_amount_ly = period.minus_1y.reconciliations.[module_name].results.[result_name] %}

In this example “module_name” and “result_name” are picked up from the arrays. The code works fine in most cases but where there is a result that does not exist we get an error. Is there a way to check if a result from the current or previous period exists that we could use to avoid this error?
Thanks!
Björn

hi @Bjorn_Lindroth ,

Thank you for your question. Can you please specify the error messages you receive? Do you receive this message when the result does not exist or when the reconciliation does not exist (and therefor the result as well).

Kind regards,

Michiel

Hi! The error we receive is:

  • Liquid error (line 445): Reconciliation Text was not found assign sub_result_amount_ly = period.minus_1y.reconciliations.[module_name].results.[result_name]
  • Liquid error (line 449): Reconciliation Text was not found assign text_array_source_ly = period.minus_1y.reconciliations.[module_name].results.[text_key_ly]
  • Liquid error (line 471): Reconciliation Text was not found assign test_value_ly = period.minus_1y.reconciliations.[template_url].results.[result_name]
  • Liquid error (line 472): Reconciliation Text was not found assign ly_value = period.minus_1y.reconciliations.[template_url].results.[result_name]*1
  • Liquid error (line 855): Reconciliation Text was not found assign allocation_amount_ly = period.minus_1y.reconciliations.avsattning_periodiseringsfond.results.total_allocation_in_books*-1

Hi @Bjorn_Lindroth

It sounds like the liquid error is related to the reconciliation not existing in that particular period. If a result does not exist, it will simply return as blank but it wouldn’t throw a liquid error.

I think you’ll need to wrap your calls to the reconciliation of the previous period inside an exists? condition to avoid this error:

{% if period.minus_1y.reconciliations.[module_name].exists? %}
  {% assign sub_result_amount_ly = period.minus_1y.reconciliations.[module_name].results.[result_name] %}
{% endif %}

I hope this helps you further!

Kind regards
Wouter

Hi,
Unfortunately this does not solve the error. I have suspected that the cause is a missing result so I also tried:

{% if period.minus_1y.reconciliations.[module_name].results.[result_name].exists? %}

But the error remains the same.

The exists? method used on the value of a result does not exist, if you want to check if the value of a result exists you should check on blanks like this:

{% if period.minus_1y.reconciliations.[module_name].results.[result_name] != blank %}

But the if-statement I shared above with exists? used on the ReconciliationDrop should normally be the solution to solve this liquid error or you could use != blank as well. I suspect you might be still calling on a non-existing reconciliation somewhere without covering it with an if-statement.

Can you reproduce this issue in a sample so we can take a look together?

Kind regards
Wouter

I have done some more testing and a combination of checking with “exists?” and checking if “result != blank” almost does the trick. The code I have is like this:

{% assign ly_value_exists = false %}
{% if period.minus_1y.reconciliations.[module_name].exists? %}
{% if period.minus_1y.reconciliations.[module_name].results.[result_name] != blank %}
{% assign ly_value_exists = true %}
{% endif %}
{% endif %}

I the use the variable “ly_value_exists” to determine which values to use. With this code I get only one error message:

Liquid error (line 23): Reconciliation Text was not found if period.minus_1y.reconciliations.[module_name].results.[result_name] != blank

As I test if every reconciliation exists, does this mean that it is the value in one of the results that is causing this? I am not sure how to dig deeper in this so any help is appreciated. When testing I have put the code in a document text for the project if that helps when looking for the cause of the error. Let me know if I should provide the url to the text.

Thanks!
Björn

I’m also not sure where the error could be occurring without more details of the code and company, but it might help to perform a check to see if the period exists?

period.minus_1y.exists?

Kind regards
Wouter

The period exists. The error only shows for this one company right now as far as I am aware and does not affect the calculations so it is not critical to solve right now. We have in some cases had to unlock and recalculate reconciliations in previous periods in order to get everything to work and I suspect that would solve this as well. But as everything else works here I do not want to risk changing amounts for previous periods so I don’t think it is worth the effort to dig further.

With the new tests for period and results the reconciliation works better so unless the error shows up somewhere else I am happy with leaving this as it is. Thanks for your input!
Regards,
Björn