cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Brazilian_Joe
Advocate II
Advocate II

ClearCollect on a fresh collection receives a record, but thinks it is a non-record.

Hi, 

 

I am using Power Automate (formerly Flow) to query Cosmos DB and format the response for PowerApps. 

(I have used the same method in other  flows and it works)

 

In this one instance however, ClearCollect is refusing the response, thinking it is not a record. 

If I Set() the response to a variable however, it is recognized as a record. 

 

If I try: 

ClearCollect(asd_col,Upsert.Run("{""pkey"":""test""}"))

The code is underlined red, with the message
The function ClearCollect has some invalid arguments.

Cannot use a non-record value in this context.

I cannot execute the code, it stays with a red underline.

 

If I try Set, however:

Set(asd_var,Upsert.Run("{""pkey"":""test""}"))

It works just fine - asd_var is defined as a record just fine. 

 

My Power Automate response to PowerApps uses a schema auto-generated from a sample response, it is well-formed and the data returned conforms to it.

 

clearcollect-record-error.png 

3 REPLIES 3
v-yutliu-msft
Community Support
Community Support

Hi @Brazilian_Joe ,

Maybe you could try this:

If(!IsBlank(Upsert.Run("{""pkey"":""test""}"))||
   !IsEmpty(Upsert.Run("{""pkey"":""test""}")),
   ClearCollect(asd_col,Upsert.Run("{""pkey"":""test""}"))
  )

In set function, if the variable is empty, it will not have error message.

While in clearcollect function, if the record is empty, it will have error message.

So I suggest you add an if statement to justify whether the result is empty record.

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

A few problems with the suggestion.

 

First, the Flow always sends a response. A well-formed response can be saved with Set() just fine, but ClearCollect refuses the same response. 

 

Second is that running Upsert three times for the same data (!!!) is not good, since there is a quota on number of Flow executions.  There are other server side automation that would happen whenever a document is upserted, and it would cascade triple triggers to other actions as well.  The flow should be run only once, and PowerApps should accept the response.

I was wondering if it would be possible without doing multiple calls to the database/flow?

 

Something like this:

 

Set(SQLSiteVisitsDATA, 'PA>usp_view_SiteVisitsPlanned'.Run());
If (IsBlank(SQLSiteVisitsDATA), ClearCollect(Data, {}) , ClearCollect(Data, SQLSiteVisitsDATA));

 

Or even better something like this:

ClearCollect(SQLSiteVisitsDATA, Coalesce('PA>usp_view_SiteVisitsPlanned'.Run(),{}))

But this fails too... Is there a way to have just one call to flow and have a collection empty or populated? See my similar question here.

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (2,269)