Conditions in Mayan

Hi there, working out the ins and outs of workflows and want to add a tag only of the document type is of certain kind. Google search brought me here but it seems the forum was rebuilt and the answer I am looking for is gone :frowning:

It seems I need to know the document type variable and grab the type from it in an if X = XX so it would be true if its the specified type or false, but where is a good place to see the available variables that can bye used in the Django templates. So I guess this could be used in any of the condition fields throughout the app.



The best place to explore the attributes, properties and fields of documents is the “Sandbox”.

1 Like

Thank you for the point in the right direction. I will poke around. Thanks!

Was able to do what I wanted after playing around in the sandbox. I had to make sure I was using the correct context. I basically wanted to “file” a document into the correct cabinet/folder depending on the document type. I was able to setup an action for the last step in the work flow, one for each document type and put the condition that matched the document type. Example, for Automotive document types I used the below statement.

{% if workflow_instance.document.document_type.label == “Automotive” %} True {% endif %}

1 Like

Hi. Thanks for pointing out how this works. At the moment I’m also trying to create conditions. I know that I can access the model’s context. For my case I need to access the user (id or username) that is currently logged in. Is there any chance to get this field?

(my usecase is that I want to make sure that a user cannot approve two successive workflow states).

Something like this:

{% if env.username == “joe” %} True {% endif %}

At the moment the current user is not injected into the template context. We’ll have to run a few scenarios to make sure doing so would not cause any sort of security issues.

The other concern is that the user would only be available during interactive use. Conditions that rely on the logged user will not work when triggered automatically from an event.

Thank you Roberto for pointing this out. Maybe is there any other way or workaround for getting the User inside the template besides the injected model? For example by calling an API request inside the template? (I don’t know if this would work). Do I have any other chance to filter out the user from a workflow transition who already approved the last state? Thanks

That almost works.

This template will give the username of the user that made the last transition:
{{ document.workflow.<workflow internal name>.get_last_log_entry.user.username }}

The current user can be obtained from the API via: /api/v4/users/current
But there is no method to inject data from the API into the running workflow context. That is an interesting improvement to add to the workflow HTTP action. Then this and other use cases can be solved from a single solution.