Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Velocity not evaluating some functions as part of workflow subactions #27815

Closed
wangweiyi722 opened this issue Mar 4, 2024 · 4 comments
Closed

Comments

@wangweiyi722
Copy link

Parent Issue

No response

Problem Statement

When running velocity code as part of a workflow subaction, some functions and properties in the code do not get evaluated into values, but are treated as strings instead.

Steps to Reproduce

Create a content type with a category field
Create a workflow with a step that includes a large message subaction which populates the content based on a vtl
Create a content of the content type
In the content search menu, select the content in question > available workflows > run the workflow step
The large message that is displayed will have some of the content fields and functions unpopulated
Go to the same content, and actually open the content edit modal.
Run the workflow from the content edit modal
The large message that is displayed will have all of the content fields

Acceptance Criteria

Make the workflows consistently populate velocity variable values

dotCMS Version

23.01.12

Proposed Objective

Technical User Experience

Proposed Priority

Priority 2 - Important

External Links... Slack Conversations, Support Tickets, Figma Designs, etc.

https://dotcms.zendesk.com/agent/tickets/115127

115127_480P.mov

Assumptions & Initiation Needs

No response

Quality Assurance Notes & Workarounds

No response

Sub-Tasks & Estimates

No response

@weiyiwang-dotcms
Copy link

In summary, we would like to understand in what cases dotCMS is able to evaluate the functions and variables, and in what cases dotCMS is not. I have not been able to achieve behavior consistent with what the customer reported. They are only running the workflows via the content edit modal, but the dotcontent.find viewtool is still only sometimes being evaluated.

@dsolistorres
Copy link
Contributor

After some internal discussion we have some guidelines regarding how to load categories in velocity code executed in a workflow action:

  • The $workflow variable intended use is for retrieving properties related to the workflow action, not properties for the content, for example:
    • task : points to the workflow task assigned to the content
    • action : points to the workflow action in execution
    • scheme : points to the workflow scheme
    • step : points to the current workflow step
    • nextAssign : role to be assigned to workflow next
    • nextStep : next step after completing the action
    • workflowMessage : message entered for the workflow action execution, if exists
  • There is no a guarantee that the contentletDependencies property is included in the $workflow variable properties, because there is another variable '$content' that can be used to retrieve the content identifier, and then the $dotcontent velocity tool can be used to retrieve a content map with all the content properties.
  • Here is an example of velocity code that can be included in a workflow sub-action to retrieve the content categories. In this example, the content field 'productName' is category field:
#set($contentMap = $dotcontent.find($content.identifier))
<h4>$!{contentMap.title}</h4>
<ul>
#foreach($cat in $contentMap.productName)
	<li><b>Category Name:</b> $!{cat.categoryName}</li>
	<ul>
		<li><i>Category Key:</i> $!{cat.key}</li>
		<li><i>Velocity Variable Name:</i> $!{cat.categoryVelocityVarName}</li>
	</ul>
#end
</ul>

@dsolistorres
Copy link
Contributor

Additional Note

The $workflow velocity variable for workflow subsections that execute velocity code isn't documented here:
Velocity Script Sub-Action
We can include the documentation for the '$workflow' variable and its properties in this page.
Also, some workflow subactions, like the 'Send Form Email' subsection, include other velocity variables for so the user can access some properties without using the $workflow variable properties. For example: $workflowMessages, $stepName and $actionName. We can do some code changes to use the same variables in all the subactions that execute velocity code, that way we will have a consistent velocity context for all the subactions.

@erickgonzalez
Copy link
Contributor

Closed in favor of: #28352

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
4 participants