cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
lardo5150
Microsoft
Microsoft

Unable to remove last character from String Variable

My flow is grabbing the work days for each user in a SPO List.

For each workday, I add it to a variable like this.

Sun,Mon,Tues,Weds

 

When I add it to the variable, I am using a comma at the end.

 

So when it gets posted to the SPO list, it actually looks like this:  Sun,Mon,Tues,Weds,

I am trying to remove the last comma, but it is not working.

Towards the end of my flow before I update the SPO item, I have a compose that is supposed to remove that last character.

I am using the same compose for another variable, and it is working fine.

substring(variables('vAssignmentDay'), 0, sub(length(variables('vAssignmentDay')), 1))
 
Any idea why it is not removing that last trailing comma?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Expiscornovus
Super User
Super User

Hi @lardo5150,

 

Below is an example of a join function to turn an array (choice field with multiple selections) into a comma separated string value.

 

1. Use a Select to retrieve the labels of the selected values of the AssignmentDays field.

 

2. In the update item action an expression is used in the WorkDays field to join these values from the select with a comma delimiter:

 

 

 

join(body('Select'), ',')

 

 

 

 

workingdays_join.png

 

The end result should look something like this.

testing_workingdays.png

 

In your setup you probably can use a couple of nested replace functions instead of the item()['Value'] in the Select action. It looks a bit quirky, but it should work.

 

 

 

replace(replace(replace(replace(replace(replace(replace(item()['Value'], '0', 'Sun'), '1', 'Mon'), '2', 'Tues'), '3', 'Weds'), '4', 'Thurs'), '5', 'Fri'), '6', 'Sat')

 

 

 

 

nestedreplacefunctions.png



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


View solution in original post

7 REPLIES 7
Expiscornovus
Super User
Super User

Hi @lardo5150,

 

Your expression looks fine. Can you show a screenshot of the values used in the flow instance which failed? Maybe there is a trailing space character which you don't see?

 

If you want to be sure you could also use a lastindexof in your expression:

substring(variables('vAssignmentDay'), 0, lastIndexOf(variables('vAssignmentDay'), ','))

 

 



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


lardo5150
Microsoft
Microsoft

So, it does not error, everything runs perfectly, I am just left with that trailing comma 🙂

lardo5150_0-1643903488044.png

FYI, as I show you this, keep in mind I was copying code from some of my other flows, so the Compose is most likely not needed but I just kept it anyways.

We check to see if the variable vSunday is equal to zero (Monday is 1, Tuesday is 2, etc.)

if it is, we do a compose (again, most likely not needed but I kept it as I was doing a copy to clipboard on everything).

concat('Sun')
 
We then add that output to the variable with a comma (I just checked, there is no space after the comma).
 
lardo5150_1-1643903684268.png

 

We do this for each day, checking if they are working that day, and add it to the variable the same each time, with a comma at the end.

 

Expiscornovus
Super User
Super User

Hi @lardo5150,

 

Thanks for your explanation. I am a bit confused, to be honest 😁.

 

Do you have that substring function to clean up the trailing comma in your current flow setup? If so, where in the flow is that located? I assume after the last append to string variable action?

 

Btw, another approach could be to create an array of working days and using a join function to turn it into a comma separated string value. With this approach you don't have to worry about a trailing delimiter.



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


lardo5150
Microsoft
Microsoft

That is a good idea.  I will see if I can rework this later on.

For the time being, if we can get the trailing comma to drop that would be great.

and yes, the compose of removing the trailing comma is at the end.

 

lardo5150_0-1643905277391.png

 

Expiscornovus
Super User
Super User

Hi @lardo5150,

 

Can you share a screenshot of your AssignmentDays column setttings in SharePoint. It is a choice field (which allows the selection of multiple values?), correct?

 

I will create a sample for you with a join function 🙂



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


lardo5150
Microsoft
Microsoft

Yes, but the way it was designed is not user friendly (I did not build up the SPO site, I just have to work with it).

So I am doing the same thing for AssignmentDays and AssignmentHours.  they are both choice columns.

Hours start at 0 up to 23 (military).

Days starts at 0 (Sunday) to 6.

 

So I am created a single line text column next to them and am putting the more user friendly values there.

You can see I did the QueueTime and the trailing comma was removed.  Not sure why it did not work for the work days as everything is the same.

 

lardo5150_0-1643906075339.png

 

Expiscornovus
Super User
Super User

Hi @lardo5150,

 

Below is an example of a join function to turn an array (choice field with multiple selections) into a comma separated string value.

 

1. Use a Select to retrieve the labels of the selected values of the AssignmentDays field.

 

2. In the update item action an expression is used in the WorkDays field to join these values from the select with a comma delimiter:

 

 

 

join(body('Select'), ',')

 

 

 

 

workingdays_join.png

 

The end result should look something like this.

testing_workingdays.png

 

In your setup you probably can use a couple of nested replace functions instead of the item()['Value'] in the Select action. It looks a bit quirky, but it should work.

 

 

 

replace(replace(replace(replace(replace(replace(replace(item()['Value'], '0', 'Sun'), '1', 'Mon'), '2', 'Tues'), '3', 'Weds'), '4', 'Thurs'), '5', 'Fri'), '6', 'Sat')

 

 

 

 

nestedreplacefunctions.png



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (2,920)