Search code examples
arraysjsonsliceextractazure-logic-apps

template language function 'slice' expects its first parameter to be of type string in logicapps Variables


I have a requirement to slice "Dev" from below variable vmName in Azure logicapp

variable information :

  • Name : vmName
  • Type : String
  • Value : Dev-Testing-2

When i tried with below approach/expression :

slice(split(variables('dsvmName'),'-'),1)

error : The template language function 'slice' expects its first parameter to be of type string. The provided value is of type 'Array'. Please see https://aka.ms/logicexpressions#slice for usage details.'.

enter image description here


Solution

  • Try this (untested) ...

    split(variables('dsvmName'),'-')?[0]
    

    That will retrieve the first item in the array when you split it by a hyphen.