Keeping Score

I am trying to create a workflow that increments a score value as actions occur within the workflow. I tried using a workflow parameter but support have said it is not possible to update a parameter during the workflow process. The score will ultimately be used as part of the decision process at the end of the workflow. I was thinking along the line of {{$workflow.[Score]}}={{$workflow.[Score]}}+10

Do you just need a place to temporarily store a value you already incremented OR is your question focused around the ability to do the incrementation math in the first place? … OR both?

Thanks for your reply

The math operation seems to work but always generates a new output. What i would like is for the score to be updated by 10 each time a check is failed and as part of the decision process if the score variable is over 50 perform an action. I am really surprised the workflow parameter can be used, but this has been confirmed by support.

I hope this makes the question make a bit more sense.

If you’re doing the analysis inside a loop, you can use a loop output for the score.
For example, if you have a “score” that’s retrieved from another system, use an array loop output to have the loop output sum them up directly. Naturally, you could then add all the different score components (from the different analysis sources/analysis steps/etc.) together with the math plugin.

I usually think of a workflow as a set of independent steps with each step adding data to a job record. Each step can use data from all the previous steps and add its own data to the record BUT because the job data is also a record recording the results of each step, one step can’t edit the result of another step. It’s a purely additive process.
So, instead of trying to track your score as you go think about setting up your score data to be added up at the end. An advantage of this approach is the score is naturally separated into its contributing parts so you can report not just on the total but on each component’s contribution to the total.

If you want or need to write out the score someplace, you can create a global artifact with two fields: id(string) and value(string or number should work). Each score you want to add up, just write to the global artifact. For the ID use the job url ({{$job.URL}} and write the score into the value field.
When you need to get the total score, do a lookup on the global artifact using the {{$job.URL}} as your search. This will return a list of all the items written by the workflow job. Then use handlebars in the math plugin to sum it up. {{#each [global artifact lookup step].[matches]}}{{this.[value]}}{{#unless @last}}+{{/unless}}{{/each}}

1 Like

I agree with @elijah_martin-merrill as it would be beneficial to break it out into its contributing parts. The only thing that I would do differently is use a Storage Plugin instead of Global Artifact, but that is just personal preference as either way will do

If all that fails, you could just use a Python or Powershell script as an alternate strategy too (cheat a bit) however Loops, Decisions, Math, Storage/Artifacts plugins should do the trick in alignment with the @elijah_martin-merrill proposed approach.

Hope this helps more than not.

I have two reservations about the storage plugin:

  1. it relies on your orchestrator so you have the round-trip time latency to contend with.
  2. to do the additive work with the storage plugin, each time you update it you have to read the value, do the math, then write the value back. That’s 3 steps for each score update and two of those steps require the orchestrator. With the global artifact approach you just write the score each time and read it all back at the end so it’s 1 step instead of 3 for each score you write.

Now that we have the delete helper for global artifacts, the only real functional difference I can think of between the GA and storage plugin approach is you have to create the global artifact first. However, if you just create one global artifact called “storage” and have two fields “key” and “value”, it can be used just like the storage plugin across multiple workflows (well, almost. json objects can’t be natively stored in global artifact strings) but updating a value is multiple steps.

My incredibly un-scientific test - storing an item in a GA was less than a second, storage plugin took 4 (on my incredibly under-resourced test orchestrator):

1 Like


The only bit i didn’t understand from your post, is how do you create a global artefact with 2 fields “you can create a global artifact with two fields: id(string) and value”

Could you elaborate on this?

On the left under Settings you have global artifacts. You can create a new global artifact of type “object” and define two fields which you can then populate and retrieve from workflows.

Think of a global artifact as a spreadsheet. You setup your spreadsheet with specific column headings before you start populating data into it. This is “creating the artifact” in ICON. After you’ve setup your spreadsheet, you can then add, remove, and read rows on the sheet. In ICON you do this with helper steps in your workflows.