Hi all,
I would really appreciate a bit of help with a compose action to change the last comma to an '&' unless there is no last comma. I have a flow that gets a list of events from a calendar we invite to any business meetings and an automated email goes out to share with our department our business meetings for the next week. The flow looks through each calendar event and pulls out the attendee names and stores that to a string variable. Before it stores that data to the string variable I do the following:
- Get the required attendees and options attendees, then do a concat to join them together
- I replace the domain name with a comma, I replace the full stop with a space, I remove the account that stores the meetings across our teams, I replace ';' with a ', ' (as some external meetings show like this) - This leaves me with Firstname Lastname, Firstname Lastname, Firstname Lastname,
Compose action (CleanAttendees): trim(replace(replace(replace(replace(replace(outputs('JoinAttendees'),'@test.com;', ','),'.', ' '),'BRMMeetings,',''),',',', '),';',', '))
- I then remove the last comma, This leaves me with Firstname Lastname, Firstname Lastname, Firstname Lastname
Compose action (removelastcomma): substring(outputs('CleanAttendees'),0,sub(length(outputs('CleanAttendees')),1))
- I then remove the last comma and replace with an '&', This leaves me with Firstname Lastname, Firstname Lastname & Firstname Lastname
Compose action (FinalNames): concat(substring(outputs('removelastcomma'),0,lastIndexOf(outputs('removelastcomma'),',')), ' & ',slice(outputs('removelastcomma'),add(lastIndexOf(outputs('removelastcomma'),','),1)))
This has been working perfectly fine for the last 6 weeks, although I hit an issue this week as someone put a placeholder in the diary, invited the calendar to the meeting and as it only had the organizer as the required attendee, there was no comma between two names as only one name exists. Therefore on the FinalNames compose action I got the error below
Unable to process template language expressions in action 'FinalNames' inputs at line '0' and column '0': 'The template language function 'substring' parameters are out of range: 'start index' and 'length' must be non-negative integers and their sum must be no larger than the length of the string. Please see https://aka.ms/logicexpressions#substring for usage details.'.
Is there a way to change the FinalNames compose action to deal with the scenarios where there is only one name? Essentially, if there is no comma then ignore. I have told the team only to include the calendar when business users have been added, but I know this mistake will happen again and cause the flow to fail, so would prefer to add the logic to deal with this.
Image of portion of flow below:
