Hi all!
It looks like the Get Index operator of the Define Variable action of Workflows is broken.
To show this, we have created a workflow with external trigger, where we pass the variable foo
with value foobarfuz
, then we define a variable barLocation
which is defined as the getIndex transform of this foo
variable, where we search for the pattern bar
. See JSON of full workflow at the bottom.
We test the workflow and notice the following:
Define Variable, step input:
{
"id": "sp:define-variable",
"variables": [
{
"description": "test",
"name": "barLocation",
"transforms": [
{
"id": "sp:transform:getIndex:int",
"input": {
"patternGetIndex": "bar"
}
}
],
"variableA": "foobarfuz"
}
]
}
Define Variable, step output:
{
"barLocation": 0
}
We would expect the value 3 instead of 0 here, since the substring bar
only appears for the first time in foobarfuz
at index 3 (we expect counting to start at 0). Actually all tests so far only returns 0.
We would also expect documentation that specifies that getIndex only returns the index of the first occurance, such that foobarfuzbar
gets 3 as result instead of 9.
We also would expect the documentation to mention the designed return value when the specified substring does not exists at all. Note that this can not be 0, as 0 would mean that the string starts with the given substring. Will it be -1, will it be null?
Full workflow json
{
"name": "Angelo test workflow get index",
"description": "test",
"modified": "2023-11-27T10:32:51.113381604Z",
"modifiedBy": {
"type": "IDENTITY",
"id": "8caf9b6efd2848c3b8b38cddae22b037",
"name": "angelo_mekenkamp"
},
"definition": {
"start": "Define Variable",
"steps": {
"Define Variable": {
"attributes": {
"id": "sp:define-variable",
"variables": [
{
"description": "test",
"name": "barLocation",
"transforms": [
{
"id": "sp:transform:getIndex:int",
"input": {
"patternGetIndex": "bar"
}
}
],
"variableA.$": "$.trigger.foo"
}
]
},
"nextStep": "End Step — Success",
"type": "Mutation"
},
"End Step — Success": {
"type": "success"
}
}
},
"creator": {
"type": "IDENTITY",
"id": "8caf9b6efd2848c3b8b38cddae22b037",
"name": "angelo_mekenkamp"
},
"trigger": {
"type": "EXTERNAL",
"attributes": {}
}
}
Trigger input:
{
"foo": "foobarfuz"
}