Using LogicApp to slice an array on indices

Tim 156 Reputation points
2022-08-10T17:54:59.4+00:00

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.

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,551 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MikeUrnun 9,777 Reputation points Moderator
    2022-08-11T00:45:45.637+00:00

    Hello @TimMolleman-2324 - Welcome & thank you for posting on MS Q&A!

    You can achieve the end goal just by using the slice() alone:

    slice(triggerBody()?['Title'], 0, 34) // will return "https://sharepoint/sites/test-site"  
      
    slice(triggerBody()?['Title'], 34) // will return "/Documents/somereport.pdf"  
    

    The two expressions above can be used separately, as-is across any Actions defined below the Trigger in your overall workflow, however, if you must consume their values from a variable, you can absolutely do so as well by running the same expressions above in conjunction with a variable of a specific type (array, string, etc.) of your choosing. For more, please review: Store and manage values by using variables in Azure Logic Apps

    I hope this helps - let me know if you have any questions!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.