Creating UDF's and adding them to the period drop

Hey,

For an internally generated template, I made an if-then structure to determine the (at most) four prepayment dates for a company.

I’d like to add this function as a method to the period drop (in order to not having to repeat myself when this functionality is used in another template); this is very comparable to putting a UDF in a module in VBA (Excel). Is this possible and - if yes - how?

Thanks!

Hey @Bart_Verhaeghe,

You can take the 4 dates into 4 result-tags (if it’s generated in a recon template), so that it can be displayed in other templates. Or did you mean you wish to take the logic-code with you in other templates?

Hi Sven,

Yes, it’s the logic-code that has to be available to other templates (so it can calculate with the dates of the period in question for the company in question) without having to repeat myself every time.

You could take that whole logic code into a capture, and that capture take into a result tag @Bart_Verhaeghe, like this :

Recon template (handle: community)


{% capture logic_code %}

{% assign current_date = period.end_date %}

{% assign new_date = current_date+9 %}

New date is {{ new_date | date:"%d-%m-%Y" }}

{% endcapture %}

{% result 'link_code' logic_code %}

Display the logic code with result in another template :


{{ period.reconciliations.community.results.link_code }} 

So, you capture your whole code into 1 capture and call your capture ’ logic_code ’ , and that capture can be taken into a result-tag :


{% result 'link_code' logic_code %} 

Care to take it a try? Hope you’re not losing any sleep over STL :expressionless:

Thanks! Great (should have thought of this myself). I’ll try it asap.

Hi Sven,

This works (although I have two small issues with this:
1.First of all, if I replace my code in the way described above, there’s an empty line above the output (which isn’t there when I define the function in the template itself); how can I solve this?
2.Is it possible to provide input parameters to a function this way (not attached to drops like period or company for example)? An example would be fiscal parameters defined in another template which would be used to make further calculations)?

If I’m not making myself clear, please ask …

Sleeping better already ;-)!

@Bart_Verhaeghe

  1. I think it would be best to post your code because use of my example code wouldn’t generate an empty line unless there’s no result tag to begin with? Then you could check if it there or not

  2. no, not really. But I don’t see a problem in this; you could always create a template named “settings” or something and guide users towards it, to fill in the needed info, no?

Hi Sven,

Code:


{% stripnewlines %}
{% capture CUS_FUN_MaakGestructureerdeMededeling %}
{% comment %}Stap: elimineer de puntjes in het BTW-nummer{% endcomment %}
  {% assign vat_identifier_beginresultaat = company.vat_identifier | replace: '.', '' %}
{% comment %}Stap: bepaal de rest bij deling door 97{% endcomment %}
  {% assign vat_identifier_restbijdelingdoor97 = vat_identifier_beginresultaat | plus:0 | modulo:97 %}
{% comment %}Stap: hang de twee delen aan elkaar (maar voeg een 0 toe om 2 cijfers te hebben indien nodig{% endcomment %}
  {% if vat_identifier_restbijdelingdoor97 < 10 %}
    {% assign vat_identifier_eindresultaat1 = vat_identifier_beginresultaat | append:'0' | append:vat_identifier_restbijdelingdoor97 %}
  {% else %}
    {% assign vat_identifier_eindresultaat1 = vat_identifier_beginresultaat | append:vat_identifier_restbijdelingdoor97 %}
  {% endif %}
{% comment %}Stap: splits vat_identifier_eindresultaat1 in drie verschillende stukken om tot het finale resultaat te komen{% endcomment %}
  {% assign vat_identifier_eindresultaat2_P1 = vat_identifier_eindresultaat1 | slice: 0, 3 | append: '/' | prepend: '+++' %}
  {% assign vat_identifier_eindresultaat2_P2 = vat_identifier_eindresultaat1 | slice: 3, 4 | append: '/' %}
  {% assign vat_identifier_eindresultaat2_P3 = vat_identifier_eindresultaat1 | slice: 7, 5 | append: '+++' %}
{% comment %}Stap: hang alle stukjes terug samen{% endcomment %}
  {% assign vat_identifier_eindresultaat2 = vat_identifier_eindresultaat2_P1 | append: vat_identifier_eindresultaat2_P2 | append: vat_identifier_eindresultaat2_P3 %}
{% comment %}Finale output{% endcomment %}
{{vat_identifier_eindresultaat2}}
{% endcapture %}
{% result 'CUS_FUN_MaakGestructureerdeMededeling' CUS_FUN_MaakGestructureerdeMededeling %}
{% endstripnewlines %}

Can’t simulate it I’m afraid @Bart_Verhaeghe

BUT avoid using the stripnewlines around your capture ? They don’t have a use in here IMO (if you want to use them, it’s better to use them within the capture).