Home > Net >  template language function 'slice' expects its first parameter to be of type string in log
template language function 'slice' expects its first parameter to be of type string in log

Time:11-28

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 enter image description here

CodePudding user response:

Try this (untested) ...

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

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

CodePudding user response:

I have reproduced in my environment and got expected results and followed below process:

Firstly, I have taken a http trigger and then initialized as below: enter image description here

Then, again I initialized as below:

indexOf(variables('vmName'), '-')

enter image description here

Then again initialized as below to get output:

substring(variables('vmName'),0, int(variables('emo')))

enter image description here

Output:

enter image description here

enter image description here

  • Related