Using .includes() or .indexOf() in Workflows for VSM
I wanted to put this out there for anyone else who might run into this and save you the research and testing I had to do to figure this out: when building Workflows for VertiGIS Studio Mobile, if you need to use .includes() or .indexOf() on any array(collection) in the Workflow, the JS methods will not work in VSM, you must modify your expressions to use the .Net methods as so:
- .includes() - Use the .Net Array.Contains() method: ex., myCollection.result.Contains(myValue)
- .indexOf() - Use a modified version of the .Net Array.IndexOf() method: ex., myCollection.result.IndexOf(myValue). NOTE: case is important! Do not confuse it with the JS method .indexOf()
Here are two sample Workflows that I tested and confirmed will work in VSM (5.22):
Using .Contains():
{
"_properties": {
"isServerWorkflow": false
},
"components": [
{
"id": 2,
"steps": [
{
"id": 3,
"inputs": {},
"position": "0,0",
"purpose": "start",
"title": "Start",
"transitions": [
{
"id": 5,
"inputs": {},
"position": "90,60 90,220",
"target": {
"id": 4
}
}
]
},
{
"action": "gcx:wf:core::CreateValue",
"id": 4,
"inputs": {
"expression": {
"accessors": [],
"annotations": [],
"code": "[\n 1,\n 2,\n 3,\n]",
"source": "[\n 1,\n 2,\n 3,\n]"
}
},
"name": "value1",
"position": "-30,150",
"title": "Create Value",
"transitions": [
{
"id": 7,
"inputs": {},
"position": "90,220 90,270",
"sourceConnector": "bottom",
"target": {
"id": 6
}
}
]
},
{
"action": "gcx:wf:core::Evaluate",
"id": 6,
"inputs": {
"expression": {
"accessors": [
"$value1"
],
"annotations": [
{
"count": 7,
"index": 0,
"kind": "idref"
}
],
"code": "$value1.result.Contains(3)",
"source": "$value1.result.Contains(3)"
}
},
"name": "evaluate1",
"position": "-30,270",
"title": "Evaluate Expression"
}
]
}
],
"deploymentConfig": {
"supportedApps": {
"GMV": true
}
},
"designerVersion": "5.32.0+12",
"licenseInfo": {
"licenseUrl": "https://vgisdev.ci.salinas.ca.us/Geocortex/Workflow/service/auth/license"
},
"start": {
"id": 3
}
}
Using .IndexOf():
{
"_properties": {
"isServerWorkflow": false
},
"components": [
{
"id": 2,
"steps": [
{
"id": 3,
"inputs": {},
"position": "0,0",
"purpose": "start",
"title": "Start",
"transitions": [
{
"id": 11,
"position": "90,60 90,110",
"sourceConnector": "bottom",
"target": {
"id": 6
}
}
]
},
{
"action": "gcx:wf:core::CreateValue",
"id": 6,
"inputs": {
"expression": {
"accessors": [],
"annotations": [],
"code": "[\n 1,\n 2,\n 3,\n]",
"source": "[\n 1,\n 2,\n 3,\n]"
}
},
"name": "value1",
"position": "-30,110",
"title": "Create Value",
"transitions": [
{
"id": 10,
"inputs": {},
"position": "90,180 90,260",
"sourceConnector": "bottom",
"target": {
"id": 8
}
}
]
},
{
"action": "gcx:wf:core::Evaluate",
"id": 8,
"inputs": {
"expression": {
"accessors": [
"$value1"
],
"annotations": [
{
"count": 7,
"index": 0,
"kind": "idref"
}
],
"code": "$value1.result.IndexOf(3)",
"source": "$value1.result.IndexOf(3)"
}
},
"name": "evaluate1",
"position": "-30,260",
"title": "Evaluate Expression"
}
]
}
],
"deploymentConfig": {
"supportedApps": {
"GMV": true
}
},
"designerVersion": "5.32.0+12",
"licenseInfo": {
"licenseUrl": "https://vgisdev.ci.salinas.ca.us/Geocortex/Workflow/service/auth/license"
},
"start": {
"id": 3
}
}
-
Much appreciated, Randy!
0 -
Thanks Randy. FWIW, and this may be less of a surprise, I've found that Server Workflows encounter something similar. It's been a bit since I've bumped into it but I'm pretty sure that the Array arrow functions made WF angry. Pretty sure I ended up rewriting some loops into my WFs last time, I'll note to give the .NET a try.
0 -
Zack Robison Workflows run via Workflow Server will have the same complications because like VSM, it's also running in .NET, not TypeScript.
0 -
I figured that was the case for Server, but honestly was a little surprised to hear that about Mobile (even though I'm pretty sure Tom has told me as much in the past... it'll stick one of these days I'm sure).
0 -
Thanks for the heads up Zack Robison & Ken Lyon regarding Workflow Server. I haven't had any projects that required Workflow Server, yet, but I am taking note...
0
Comments
5 comments