Best practices - Groovy script workflow
I just thought I’d share some nice things I found with groovy, it’s a pretty great language.
For example, how to manage attribute creation without too much overhead:
def attributeRequests = [
[typeId: descriptionTypeUuid , value: description?.toString()],
[typeId: dueDateTypeUuid , value: dueDate? Date.getMillisOf(dueDate):null]
].findAll{it.value}.collect{
AddAttributeRequest.builder()
.assetId(request.id)
.typeId(it.typeId)
.value(it.value)
.build()
}
attributeApi.addAttributes(attributeRequests)
Nice, simple, elegant. I LIKE! 
What are your interesting snippets that make your workflow development easier?
arthurburkhardt
3 comments
arthurburkhardt
OPInsert images into a workflow textarea.
I can’t believe the textarea workflow form does not have the same behavior as the base asset edit capabilities: i.e. upload images and convert pasted images. It’s the kind of inconsistencies that makes the platform look bad when discussing with stakeholders.
Anyways, here’s the workaround for workflows:
PS: wheeew, it seems it sends the influitive syntax highlighter in for a loop.
pmahend3
This is great stuff. Coming from a Java background myself, I have to agree that scripting languages are pretty neat. I look at some of the code my colleagues write and it amazes me how many extra lines I end up writing.
I finally got a chance to speak with Tom from Algonquin College on a coaching call and we both had the same question - How does Arthur get time to diligently do all the research for his posts here?
arthurburkhardt
OPHahah, thanks, appreciate it.
Well, automating workflow development/deployment has definitely freed up some time.
I noticed in the recent releases of the java sdk the apparition of some interesting methods like the
WorkflowTaskApi.getVariables(UUID taskId), which definitely helps to understand what happens to workflow tasks being left to themselves.The workflow can be started on any asset, looks up related workflowtasks, the user selects the one they want, and the workflow will show the variables in that workflow task.