I'm trying to achieve something in LogicApp which I think should be quite easy to achieve, but I'm not managing it.
Say I have a variable from a previous step: 'https://sharepoint/sites/test-site/Documents/somereport.pdf'. From this string, I need to simply create two variables, the first one containing 'https://sharepoint/sites/test-site'
, the second one containing 'Documents/somereport.pdf'
. Both to be used in subsequent steps.
To try and achieve this I try to use the following expressions:
join(slice(split(triggerBody()?['Title'], '/'), 0, 5), '/')
join(slice(split(triggerBody()?['Title'], '/'), 5), '/')
However, I get an error: 'The template language function 'slice' expects its first parameter to be of type string. The provided value is of type 'Array'.
.
This since the split results in an array. I've now learned that 'slice' is meant for strings, but is there any similar functionality for an array type? Or is there any other (simple) way to achieve this? This seems like it should be basic functionality but I cannot figure it out.
CodePudding user response:
This can be achieved through few ways. If you are trying to use a functionality taking the result as array type then you can use something like below expression.
1. join(take(split(outputs('Compose')?['Title'][0], '/'), 5),'/')
2. join(take(skip(split(outputs('Compose')?['Title'][0], '/'),5), length(split(outputs('Compose')?['Title'][0], '/'))),'/')
However, As an alternative, below is another expression that satisfies your requirement if you are trying to use a functionality taking the result as string type.
1. slice(outputs('Compose')?['Title'][0],0,nthIndexOf(outputs('Compose')?['Title'][0],'/',5))
2. slice(outputs('Compose')?['Title'][0],add(nthIndexOf(outputs('Compose')?['Title'][0],'/',5),1),length(outputs('Compose')?['Title'][0]))
Below is my logic app
RESULTS:
Below is the code-view of my logic app
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": {
"Title": [
"https://sharepoint/sites/test-site/Documents/somereport.pdf"
],
"age": 30,
"name": "John"
},
"runAfter": {},
"type": "Compose"
},
"array_type_-_first_part": {
"inputs": "@join(take(split(outputs('Compose')?['Title'][0], '/'), 5),'/')",
"runAfter": {
"string_type__second_part": [
"Succeeded"
]
},
"type": "Compose"
},
"array_type_-_second_part": {
"inputs": "@join(take(skip(split(outputs('Compose')?['Title'][0], '/'),5), length(split(outputs('Compose')?['Title'][0], '/'))),'/')",
"runAfter": {
"array_type_-_first_part": [
"Succeeded"
]
},
"type": "Compose"
},
"string_type_-_first_part": {
"inputs": "@slice(outputs('Compose')?['Title'][0],0,nthIndexOf(outputs('Compose')?['Title'][0],'/',5))",
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "Compose"
},
"string_type__second_part": {
"inputs": "@slice(outputs('Compose')?['Title'][0],add(nthIndexOf(outputs('Compose')?['Title'][0],'/',5),1),length(outputs('Compose')?['Title'][0]))",
"runAfter": {
"string_type_-_first_part": [
"Succeeded"
]
},
"type": "Compose"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}