How to access workflow transition field from action

Questions, comments, discussions. Over time certain topics might be moved to their own category.
Post Reply
will
Posts: 1
Joined: Wed Dec 18, 2019 10:59 pm

How to access workflow transition field from action

Post by will »

Hi there,

How do I go about accessing the value of a workflow transition field from a state action?

For example, if I create a transition field called "test_field", how would I get the content of that field via a template (say to use as part of an HTTP post payload)? I guess something like {{ document.workflow.test_field }} but I've tried several without any success, and can't find anything in the docs.

Many thanks in advance.

User avatar
rosarior
Developer
Developer
Posts: 505
Joined: Tue Aug 21, 2018 3:28 am
Location: Puerto Rico
Contact:

Re: How to access workflow transition field from action

Post by rosarior »

Hi,

The variable name is {{ workflow_instance_context }}. This variable is a dictionary and contains the following keys: document (the current document of the running workflow instance), workflow (the workflow template of the running workflow instance), workflow_instance (A reference to the running workflow instance). Any transition field will be injected into the {{ workflow_instance_context }} using the field's name as the key.

If a field with name "first_name" and label "First name" is created, then it is accesses as {{ workflow_instance_context.first_name }}.

Issue #727 (https://gitlab.com/mayan-edms/mayan-edms/issues/727) was created to track the task of improving how this is documented.

Hope this helps.

marcosribeirobr
Posts: 4
Joined: Thu Nov 28, 2019 7:37 pm

Re: How to access workflow transition field from action

Post by marcosribeirobr »

Hi,

@rosarior what is the content access variable of workflow comments? And where can we find these variables for use?

Thank you and congratulations for the work!

User avatar
rosarior
Developer
Developer
Posts: 505
Joined: Tue Aug 21, 2018 3:28 am
Location: Puerto Rico
Contact:

Re: How to access workflow transition field from action

Post by rosarior »

Hi,

These variables are not officially exposed yet but can be obtained using:

Code: Select all

{% for log_entry in workflow_instance.log_entries.all %}
{{ log_entry.comment }}
{% endfor %}
The workflow model also has a method to obtain the last log entry which correlates to the last transition executed. Try this on the template:

Code: Select all

{{ workflow_instance.get_last_log_entry.comment }}
This is untested.

marcosribeirobr
Posts: 4
Joined: Thu Nov 28, 2019 7:37 pm

Re: How to access workflow transition field from action

Post by marcosribeirobr »

Thanks @rosarior !

One last question. What would be the variable responsible for the name of the logged in user?

I am making a template for email and informing the user name would be excellent.

j_arquimbau
Posts: 6
Joined: Wed Feb 19, 2020 2:42 pm

Re: How to access workflow transition field from action

Post by j_arquimbau »

marcosribeirobr wrote:
Fri Feb 14, 2020 5:20 pm
Thanks @rosarior !

One last question. What would be the variable responsible for the name of the logged in user?

I am making a template for email and informing the user name would be excellent.
Hi @marcosribeirobr! Did you finally manage to get that variable for the username?

marcosribeirobr
Posts: 4
Joined: Thu Nov 28, 2019 7:37 pm

Re: How to access workflow transition field from action

Post by marcosribeirobr »

j_arquimbau wrote:
Thu Feb 20, 2020 3:25 pm
marcosribeirobr wrote:
Fri Feb 14, 2020 5:20 pm
Thanks @rosarior !

One last question. What would be the variable responsible for the name of the logged in user?

I am making a template for email and informing the user name would be excellent.
Hi @marcosribeirobr! Did you finally manage to get that variable for the username?
Hi @j_arquimbau! I still don't have the answer.

Are you also trying to locate the variable?

marcosribeirobr
Posts: 4
Joined: Thu Nov 28, 2019 7:37 pm

Re: How to access workflow transition field from action

Post by marcosribeirobr »

marcosribeirobr wrote:
Fri Feb 14, 2020 5:20 pm
Thanks @rosarior !

One last question. What would be the variable responsible for the name of the logged in user?

I am making a template for email and informing the user name would be excellent.
Hi,

@rosarior, could you help us with the above question? Thanks

Post Reply