How to remove Whitespace from PowerAutomate Compose action output?

386 Views Asked by At

I have a Power Automate workflow which takes fields from Sharepoint lists and puts them into a pdf using the Compose action to create HTML and then convert to a pdf. There are a bunch of conditions within the Compose action such as:

if sharepoint_field = 'Yes' then 'Show this' else '' Since I have a bunch of these blank strings, it is adding a lot of random whitespace between text in the final output. Is there a way I can remove the whitespace and blanks that are added due to all the conditions after the Compose action in Power Automate before it is converted to a pdf?

These if then else statements are in separate

tags and wrapping each of them in a trim still creates line breaks so I'm guessing the cleaning up of whitespace will have to happen after the compose action

multiple paragraph tags with if then else statements

This is what the expressions look like:

<p><b> trim(if(equals(outputs('Get_item')?['body/SharepointField/Value'], 'Yes'), 'Details:','')) 
</b> <span...> trim(if(equals(outputs('Get_item')?['body/SharepointField/Value'], 'Yes'), outputs('Get_item')?['body/SharepointField'],''))</span></p>

So inside the <b> tags is the Question, and I want it to print the Question only if SharepointField Value is 'Yes' then inside the span tags is the answer if Sharepoint Field value is 'Yes', if it gets to the else tag then it is just a blank. so multiple of these blanks add up and create a bunch of blank space in my final pdf.

This is the output pdf:output pdf showing all the space between the p tags which I want to get rid of

1

There are 1 best solutions below

2
Sam Nseir On

Thanks for the update to the question. You are going to have to add all your html in the if statement....

if(equals(outputs('Get_item')?['body/SharepointField/Value'], 'Yes'),
concat('<p><b>Details:</b> <span...>', outputs('Get_item')?['body/SharepointField'], '</span></p>'),
''
)

Leaving the below just in case it helps others...

I suspect it isn't the blank strings in the if statements, but the white space between your tags in the Compose action. Sharing a screen shot of your Compose would be helpful.

For example, the blue "-" is a line break, the blue "|" is a space enter image description here So maybe look to remove all white space between your tags, and add the required whitespace within your if statements. Like: enter image description here And your if statement could then be like:

if sharepoint_field = 'Yes' then 'Show this ' else ''

or if needing a line break:

if sharepoint_field = 'Yes' then concat('Show this', decodeUriComponent('%0A')) else ''