How to correctly display multiple checkboxes in Word Template - Power Automate
Asked Answered
S

1

7

After three weeks of long research I have not yet found anything related that can help me represent the selected values of a Checkbox in my Word template, so I dared to try to make on my own a possible solution that is not yet fully resolved, so I share what I have advanced and the result I have obtained so far.

I decided to first initialize a variable of type String with the value of a selected box as follows:

enter image description here

Then initialize another variable of equal type string but without an assigned value.

enter image description here

Then I attach to the string variable the values of the sharepoint column I'm using within one step of Apply to each.

enter image description here

I set variable with the variables I declare at the beginning.

enter image description here

And finally in the step where I fill the Word document I make use of the previously declared variable.

enter image description here

The result I get in the completed document at the end is that all the values appear with the box as if they had been selected.

enter image description here

Here the result is not what I expected, since I am selecting all the values when I have only selected two values.

I want to think that I am close to achieving it, I hope that someone can give me guidance at this point of how to achieve it.

Sensory answered 18/10, 2022 at 2:43 Comment(0)
C
1

How to correctly display multiple checkboxes in Word Template - Power Automate?

Power Automate is a service that allows you to automate workflows across different applications and services. One of the features of Power Automate is the ability to create and populate Word templates with dynamic data from various sources.

One of the challenges of using Word templates with Power Automate is how to correctly display multiple checkboxes based on the data. For example, if you have a Word template with a list of skills and you want to check the ones that the user has selected from a form, how do you do that?

The solution

The solution is to use a special syntax in the Word template that tells Power Automate how to handle the checkboxes. The syntax is:

{Checkbox:Value:CheckedSymbol:UncheckedSymbol}

Where:

  • Checkbox is the name of the checkbox field in the data source
  • Value is the value that the checkbox field should match to be checked
  • CheckedSymbol is the symbol or character that you want to use to represent a checked checkbox
  • UncheckedSymbol is the symbol or character that you want to use to represent an unchecked checkbox

For example, if you have a data source with a field called Skills that contains a comma-separated list of skills, and you want to use X and O to represent checked and unchecked checkboxes, you can use the following syntax in the Word template:

{Skills:Python:X:O} Python
{Skills:Java:X:O} Java
{Skills:C#:X:O} C#
{Skills:JavaScript:X:O} JavaScript

This will result in the following output in the Word document, depending on the value of the Skills field:

X Python O Java X C# O JavaScript

The explanation

The reason why this syntax works is because Power Automate uses a feature called Content Controls to map the data fields to the Word template. Content Controls are placeholders that you can insert in a Word document to display dynamic data. You can create Content Controls manually in Word by using the Developer tab, or you can use Power Automate to create them automatically based on the data source.

When Power Automate creates Content Controls, it assigns them a tag that matches the name of the data field. For example, if you have a data field called Name, Power Automate will create a Content Control with the tag Name. You can see the tag of a Content Control by selecting it and looking at the Properties panel in the Developer tab.

The syntax that we used in the Word template is actually a way of modifying the tag of the Content Control to include some additional information. By using the colon (:) as a separator, we can tell Power Automate to split the tag into four parts: Checkbox, Value, CheckedSymbol, and UncheckedSymbol. Power Automate then uses these parts to determine how to display the checkbox based on the data.

The first part, Checkbox, is the name of the data field that contains the checkbox value. Power Automate will look for this field in the data source and compare it to the second part, Value. If the data field matches the Value, Power Automate will display the third part, CheckedSymbol, as the checkbox symbol. If the data field does not match the Value, Power Automate will display the fourth part, UncheckedSymbol, as the checkbox symbol.

This way, you can create multiple checkboxes in the Word template that correspond to different values in the data source, and Power Automate will check or uncheck them accordingly.

The examples

To illustrate how this solution works, let's look at some examples of different data sources and Word templates, and the resulting Word documents.

Example 1: A simple yes/no checkbox

Suppose you have a data source with a field called Agree that contains either Yes or No, and you want to create a Word template with a checkbox that is checked if the user agrees and unchecked if the user disagrees. You can use the following syntax in the Word template:

{Agree:Yes:☑:☐} I agree to the terms and conditions.

This will result in the following output in the Word document:

☑ I agree to the terms and conditions. (if Agree is Yes) ☐ I agree to the terms and conditions. (if Agree is No)

Example 2: A multiple choice checkbox

Suppose you have a data source with a field called Color that contains one of the following values: Red, Green, Blue, or Yellow, and you want to create a Word template with four checkboxes that are checked if the user selects the corresponding color and unchecked otherwise. You can use the following syntax in the Word template:

{Color:Red:☑:☐} Red
{Color:Green:☑:☐} Green
{Color:Blue:☑:☐} Blue
{Color:Yellow:☑:☐} Yellow

This will result in the following output in the Word document:

☑ Red ☐ Green ☐ Blue ☐ Yellow (if Color is Red)

☐ Red ☑ Green ☐ Blue ☐ Yellow (if Color is Green)

☐ Red ☐ Green ☑ Blue ☐ Yellow (if Color is Blue)

☐ Red ☐ Green ☐ Blue ☑ Yellow (if Color is Yellow)

Example 3: A checkbox with multiple values

Suppose you have a data source with a field called Skills that contains a comma-separated list of skills, and you want to create a Word template with a list of skills and checkboxes that are checked if the user has the skill and unchecked otherwise. You can use the following syntax in the Word template:

{Skills:Python:☑:☐} Python
{Skills:Java:☑:☐} Java
{Skills:C#:☑:☐} C#
{Skills:JavaScript:☑:☐} JavaScript

This will result in the following output in the Word document:

☑ Python ☐ Java ☑ C# ☐ JavaScript (if Skills is Python,C#)

☐ Python ☑ Java ☐ C# ☑ JavaScript (if Skills is Java,JavaScript)

☑ Python ☑ Java ☑ C# ☑ JavaScript (if Skills is Python,Java,C#,JavaScript)

☐ Python ☐ Java ☐ C# ☐ JavaScript (if Skills is empty or none of the above)

Connotative answered 29/10, 2022 at 10:52 Comment(2)
Thank you very much for taking the time to write your answer, it is very complete in terms of its explanation, but I am having a problem adding the special syntax. It is my Word template, which content control should I use to add the syntax? Thank youSensory
Do you have any news regarding my last comment, only that is pending to validate your answer?Sensory

© 2022 - 2024 — McMap. All rights reserved.