Populating custom drops through code

Hi,

I would like to be able to populate custom drops through code instead of needing the user to provide input explicitly.
i.e., I would like to assign a value to a custom drop programmatorically, e.g.

{% if some_variable == 'acme' %}
{% assign period.custom.foo.bar = 'Some value' %}
{% endif %}

However, using assign does not save the value on the custom drop.
Is there some way to achieve this?

Thanks in advance.

Best regards,
Robin

Hello @robin.bailleul,

I need to run this by @Tim how yourself can make custom drops in STL.

Sven

Hi @robin.bailleul

It’s not possible to save a value in the database based on a computation. What would you like to use this for? There might be other ways to accomplish the end goal.

Hi @Tim,

Thanks for your answer.

We would like to use this to compute values once and store them for later usage (in other templates), so we do not need to duplicate the code performing the computations in multiple templates.
Also, we would like to initiate some input fields through code to some computed values, so a dynamic value is filled in before the user provides input. I know this second goal can be accomplished by capturing/assigning a variable and setting it as default for the input, but that value is then not available in other templates either, since the custom drop does not actually save the default value for that input but stays ‘blank’ until input is explicitly saved, so we would again need to duplicate the code performing the computations everywhere we need the dynamic values to be displayed.

I see that the API allows to populate the custom drops for company, company.people as well as period.reconciliation, (not for period-drops). So it is possible to calculate and save a value in these custom drops from my own software through the API, but not from a template script?

Best regards,
Robin

Hi @robin.bailleul

You can actually compute values and put them in a ‘result’, this means that it can be used in other templates (see the result tag at the bottom of the page https://github.com/GetSilverfin/sf-templates (we use this for example in the template ‘verworpen uitgaven’ to expose that to the ‘belastingsberekening’).

I think with the result tag you should be able to do what you want (but you can’t have circular references).

When you fill in a value with the API, the action is more similar to someone typing something in the browser, then a template calculating something.

Hi @Tim,

Thanks for pointing me towards the result tag!

This can indeed help me to exchange computed values from a reconciliation template to a different template.
Is it also possible to save values with a result-tag in Text templates?

BR,
Robin

HI @robin.bailleul

You can’t save them, but then again, why would you want to? As you can consult them anyway.