Select to view content in your preferred language

Survey123 & Power Automate: Initialize a variable and condition for optional image attachment

2218
9
Jump to solution
10-19-2023 06:20 AM
leahmaps
Frequent Contributor

Hello!

I am trying to set up a variable and condition in Power Automate to return a string if an image was attached. 

This is the list of what survey123 returns for attachments (also global ID which did not fit). Is there any of these that would work for the condition to notice if it is empty?

leahmaps_0-1697721313497.png

From there,

- if it is empty, the condition should return a string that says no image was submitted

- if it isn't empty, the condition should return a string that says an image was submitted. 

I tried this with feature attachments screenshotAttach, and feature attachments screenshotAttach id. Neither worked, and screenshotAttach id also added an apply to all block, which shouldn't be necessary.

I am trying to find a workaround from this work flow of attaching images with the HTTP block . We do not have the ability to get Power Automate premium. It is fine if there is no image attached, just a message stating whether or not one was submitted.

Thanks to anyone for suggestions!

 

0 Kudos
1 Solution

Accepted Solutions
abureaux
MVP Frequent Contributor

I mixed up the paths before (opps!). That may have thrown you of.If you swap "is equal to" to "is not equal to", that would fix it. Disregard. I got the order in my post right both times. Dyslexia is a nuisance. 

Alternatively, see below.

I just published a test from the web interface and tried remaking the flow - everything appears to work.

I also inspected the JSON for the web submission just to see if anything differed from a desktop submission, and it appears fine. However, I did realize you can probably just reference attachments (triggerOutputs()?['body/feature/attachments']), but that shouldn't really matter.

I have confirmed that the flow below does work and the paths are correct:

Base Power Automate:

abureaux_7-1697747197012.png

With an image attached:
abureaux_1-1697746992257.png

With NO image attached:

abureaux_5-1697747066958.png

 

 Edit: If you'd like to check this for yourself, try this:

  1. Submit two forms back-to-back: One with an attachment, and one without
  2. For both runs, expand the Trigger and copy the body (e.g., see below)
    abureaux_0-1697747718805.png
  3. Paste the body into VS Code (highly recommended, but Notepad++ can also work)
  4. Compare the two, and you should notice some nulls (e.g., see below - this is why I pointed to "attachments" for the logic test. However, "attachments" will likely only work if you have a single image question. My original post where I point to a question name is probably more future-resistant)
    abureaux_1-1697747994817.png

     

View solution in original post

0 Kudos
9 Replies
abureaux
MVP Frequent Contributor

I would suggest setting up a variable in Survey123, as that makes life much easier for tasks like this.

The variable in S123 can look different depending on how your image question is set up (either a lone image, a multiline image, or an image in a repeat). Here is how each of those scenarios could look:

abureaux_0-1697728900669.png

 

This makes your Power Automate flow far more straight forward while avoiding a potentially unnecessary Apply to Each:
abureaux_2-1697729191108.png

 

 

0 Kudos
leahmaps
Frequent Contributor

Yes, my plan was to set up a variable (as stated in the original post). But what does the condition have to look for from the survey attributes to see if the attachment is empty or not?

The variable is what the yes or no condition will be filled with, but the condition is where the problem starts.

0 Kudos
abureaux
MVP Frequent Contributor

I'd suggest having another look at my original post.

  1. You set up a variable in your survey (e.g., image1_test) which tests weather or not an image was taken (I've given you examples for all three formats of the image question)
    abureaux_1-1697729691047.png
  2. In Power Automate, you use that S123 variable (e.g., image1_test) in your Condition
    abureaux_0-1697729660767.png

     

0 Kudos
leahmaps
Frequent Contributor

Yes, I understand that, but our variables do not look the same. 

leahmaps_1-1697738464811.png

leahmaps_3-1697738648157.png

leahmaps_4-1697738678856.png

so which of the dynamic content will actually return an empty field or not?

What makes sense is using ID or URL or whatever should be empty if no image is submitted. There for, without having "choose a value" filled in should return to empty. Is that not how attachments are submitted? Do you need "is (not) equal to 1" in there for it to run?

I am not building the survey in connect like you are, I am in the web browser and not pushing this out to connect.

 

 

This is my list of possible variables from the attachment field in the survey123 WEB form. I have used any of the bottom three, but Power Automate is still always detecting it as an attachment being present, even if there isn't one. 

 

 

0 Kudos
leahmaps
Frequent Contributor

leahmaps_0-1697738948852.png

The image submission is just from the standard drop box. If there is anything submitted, PA should return "attachment included", if nothing was submitted, "no attachment included". There is no regard here for how many images.

0 Kudos
abureaux
MVP Frequent Contributor

Okay, this is a very different scenario.

To do this 100% inside of Power Automate while avoiding an Apply to Each, you will want to pick your question's name as the condition and test if that is null.

 

You should be able to copy-paste this into the Condition (in my example below, my question name is image1)

triggerOutputs()?['body/feature/attachments/screenshotAttach']

 

 

abureaux_0-1697743509282.png

 

0 Kudos
leahmaps
Frequent Contributor

I was hopeful, but no, that did not work. 

Here is my test submission: 

leahmaps_0-1697745763729.png

And the email response with "No image was submitted"

leahmaps_1-1697745786468.png

Here is the flow: 

leahmaps_2-1697745876969.png

 

The submission I tried with this detected that the image submission was null, and there was no image. This is the opposite of what happened before, where every submission had an image. Notice anything that might be wrong?

 

0 Kudos
abureaux
MVP Frequent Contributor

I mixed up the paths before (opps!). That may have thrown you of.If you swap "is equal to" to "is not equal to", that would fix it. Disregard. I got the order in my post right both times. Dyslexia is a nuisance. 

Alternatively, see below.

I just published a test from the web interface and tried remaking the flow - everything appears to work.

I also inspected the JSON for the web submission just to see if anything differed from a desktop submission, and it appears fine. However, I did realize you can probably just reference attachments (triggerOutputs()?['body/feature/attachments']), but that shouldn't really matter.

I have confirmed that the flow below does work and the paths are correct:

Base Power Automate:

abureaux_7-1697747197012.png

With an image attached:
abureaux_1-1697746992257.png

With NO image attached:

abureaux_5-1697747066958.png

 

 Edit: If you'd like to check this for yourself, try this:

  1. Submit two forms back-to-back: One with an attachment, and one without
  2. For both runs, expand the Trigger and copy the body (e.g., see below)
    abureaux_0-1697747718805.png
  3. Paste the body into VS Code (highly recommended, but Notepad++ can also work)
  4. Compare the two, and you should notice some nulls (e.g., see below - this is why I pointed to "attachments" for the logic test. However, "attachments" will likely only work if you have a single image question. My original post where I point to a question name is probably more future-resistant)
    abureaux_1-1697747994817.png

     

0 Kudos
leahmaps
Frequent Contributor

Alrighty, not sure what really changed between the last attempt and this one: I really only changed the condition value and sent through some test surveys, but it appeared to work. Thank you!

 

0 Kudos