cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
koperek7
Regular Visitor

How to handle empty response?

Hi,


I’m having a problem with canvas application.

In my App, I have a filter panel, so user is able to filter everything what they want. Then ‘Search’ button invokes power automate flow, execute SQL stored procedure, and output data are send back to Power Apps - that it’s fine.

The output is displayed in a power apps gallery. Everything works fine as long as the returned result is not empty. It’s not an issue when output is empty, it just means that no records in sql were found for selected criteria.

Once the output is empty, Then the problem starts with my gallery and the fields that are referring or expecting always non-empty values.

As you can see on the attached window, there is a Red Cross icon next to my fields in a gallery, which display values that should come within output?

 

the question is how to handle empty responses in a gallery, and avoid showing it as an error or something??

the error message I got is: “MyFlow.Run failed: the data returned in the response is invalid. Response data should be a valid JSON object”

 

just to remind you, it happens only when the called procedure returns empty results.

When I Call a procedure with a data which exists in a database, then of course everything is fine with the output and the gallery which displays it.

 


Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
v-bofeng-msft
Community Support
Community Support

Hi @koperek7 :

The point is that an error occurs when the response's body is null. So you can first set a judgment condition, when the value of the target parameter is null, use an empty array instead . For example:

vbofengmsft_0-1643001755742.png

if(
  equals(outputs('Compose_2'),null),
  json('[]'),
  outputs('Compose_2')
)

On your side , you could replace outputs('Compose_2') with the return value of 'executing the stored procedure' action.

Best Regards,

Bof

 

View solution in original post

1 REPLY 1
v-bofeng-msft
Community Support
Community Support

Hi @koperek7 :

The point is that an error occurs when the response's body is null. So you can first set a judgment condition, when the value of the target parameter is null, use an empty array instead . For example:

vbofengmsft_0-1643001755742.png

if(
  equals(outputs('Compose_2'),null),
  json('[]'),
  outputs('Compose_2')
)

On your side , you could replace outputs('Compose_2') with the return value of 'executing the stored procedure' action.

Best Regards,

Bof

 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (2,439)