InvalidTemplate Unable to process template language expressions in action…
- User
InvalidTemplate Unable to process template language expressions in action 'Gerar_Iniciais' inputs at line '0' and column '0': 'The template language expression 'if( empty(trim(variables('NomeRemetente'))), 'ZZ', concat( substring(first(split(trim(variables('NomeRemetente')), ' '))?[0], 0, 1), substring(last(split(trim(variables('NomeRemetente')), ' '))?[0], 0, 1) ) )' cannot be evaluated because property '0' cannot be selected. Property selection is not supported on values of type 'String'. Please see https://aka.ms/logicexpressions for usage details.'.
this is in microsoft power automate.
Assistant
This error occurs because you're trying to access array elements incorrectly in your Power Automate expression. The issue is with how you're using the
?[0]syntax.Here's the corrected expression:
if( empty(trim(variables('NomeRemetente'))), 'ZZ', concat( substring(first(split(trim(variables('NomeRemetente')), ' ')), 0, 1), substring(last(split(trim(variables('NomeRemetente')), ' ')), 0, 1) ) )The key changes:
- Removed
?[0]afterfirst()andlast()functions first()andlast()already return single string values from the array, not arrays themselves- You can't use array indexing on a string value, which was causing the error
This expression will:
- Check if the name is empty or just whitespace
- If empty, return 'ZZ'
- If not empty, take the first letter of the first word and first letter of the last word to create initials
For example:
- "John Doe" → "JD"
- "Mary Jane Smith" → "MS"
- "" or " " → "ZZ"
- Removed
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.