cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
priyankbhat
Level: Powered On

ClearCollect or Collect is throwing incompatible type error

Hi,

 

I have encountered strange issue. I wrote small tool in power app which pulls data from 2 sharepoint list and then prepares custom collection using manupulated data.

 

2 days back script was functioning flawless and not even single error was seen in powerapps designer.

 

Yesterday when i opened tool to make some enhancements i came accross below error. Please suggest how could cause error and how to fix it.

Capture.JPG

 

On next screen where i am getting error i am copying above collection to new collection so that i do not distroy dataset identified earlier.

 

Below error is appearing when i am using clearcollect.

capture 1.png

 

I modified code and moved for ForAll and using collect and still i am getting same error.

capture 2.png

 

Except isactive all are text fields, isactive is Yes/No field as per sharepoint. UserChoice is updated based on onscreen selection using patch command.

 

If(CountRows(NextItems)>0,Patch(AttemptedItem, First(CurrentItem),{UserChoice:Mid(Radio1.Selected.Value,1,1)})

I tried renaming NextItems collection name to NextItem. Within few seconds after modification i start getting above error message.

 

I went through all locations where NextItems collection is updated/called and I dont see any data type is changing.

 

Please suggest what could cause this error and how to resolve it.

 

Thanks

 

Priyank

 

 

 

 

2 REPLIES 2
Community Support Team
Community Support Team

Re: ClearCollect or Collect is throwing incompatible type error

Hi @priyankbhat,

 

Could you please share a bit more about the data structure of the NextItems collection that you mentioned?

Do you have defined the NextItems collection before the QuestionList collection?

 

The error message told that the data type of the QuestionList collection does match that within the NextItems collection. Please check if you have provided proper value for columns within the NextItems collection.

 

I have made a test on my side, and don't have the issue that you mentioned. Please take a try with the following workaround:

 

Modify your formula as below:

 

ForAll(
RenameColumns(
RenameColumns(
RenameColumns(
RenameColumns(
RenameColumns(
RenameColumns(
RenameColumns(
RenameColumns(
RenameColumns(
RenameColumns(
RenameColumns(QuestionList,"ID","ID1"),
"KnowledgeArea","KnowledgeArea1"),
"Question","Question1"),
"OptionA","OptionA1"),
"OptionB","OptionB1"),
"OptionC","OptionC1"),
"OptionD","OptionD1"),
"OptionE","OptionE1"),
"Answer","Answer1"),
"IsActive","IsActive1"),
"UserChoice","UserChoice1"
),
Collect(
NextItems,
{
RowID:ID1,
KnowledgeArea:KnowledgeArea1,
Question:Question1,
OptionA:OptionA1,
OptionB:OptionB1,
OptionC:OptionC1,
OptionD:OptionD1,
OptionE:OptionE1,
Answer:Answer1,
IsActive:IsActive1,
UserChoice:UserChoice1
}
)
)

Note: Please make sure that the QuestionList collection has already been defined before the NextItems collection.

 

In addition, please also take a try to create a new collection within your app with the following formula:

ForAll(
    RenameColumns(
        RenameColumns(
            RenameColumns(
                RenameColumns(
                    RenameColumns(
                           RenameColumns(
                                 RenameColumns(
                                      RenameColumns(
                                             RenameColumns(
                                                   RenameColumns(
                                                       RenameColumns(QuestionList,"ID","ID1"),
                                                   "KnowledgeArea","KnowledgeArea1"),
                                             "Question","Question1"),
                                     "OptionA","OptionA1"),
                                "OptionB","OptionB1"),
                           "OptionC","OptionC1"),
                    "OptionD","OptionD1"),
                "OptionE","OptionE1"),
            "Answer","Answer1"),
       "IsActive","IsActive1"),
"UserChoice","UserChoice1"
),
    Collect(
        NewCollectionName, /* <--- New Collection Name */
        {
         RowID:ID1,
         KnowledgeArea:KnowledgeArea1,
         Question:Question1,
         OptionA:OptionA1,
         OptionB:OptionB1,
         OptionC:OptionC1,
         OptionD:OptionD1,
         OptionE:OptionE1,
         Answer:Answer1,
         IsActive:IsActive1,
         UserChoice:UserChoice1
        }
    )
)

then check if the issue still exists.

 

 

Best regards,

Kris

 

 

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
priyankbhat
Level: Powered On

Re: ClearCollect or Collect is throwing incompatible type error

Hi @v-xida-msft

 

Question bank data is loaded prior. So here is subset code from my apps.

 

There are 2 screen

 

Form 1: (selection screen)

Clear(QuestionData);
ForAll(Shuffle(QuestionPaper),Collect(QuestionData,{ID:ID, KnowledgeArea:KnowledgeArea, Question:Question, OptionA:OptionA, OptionB:OptionB, OptionC:OptionC, OptionD:OptionD, OptionE:OptionE, Anwer:Anwer, IsActive:IsActive, UserChoice:"", ItemID:CountRows(QuestionData)+1}));

Form 2: (assessment screen)

Onvisible

Clear(RestoreData);
Clear(NextDataDb2);
ForAll(QuestionData, Collect(NextDataDb2, {ID:ID, KnowledgeArea:KnowledgeArea, Question:Question, OptionA:OptionA, OptionB:OptionB, OptionC:OptionC, OptionD:OptionD, OptionE:OptionE, Anwer:Anwer, IsActive:IsActive, UserChoice:UserChoice,ItemID:ItemID}));
ClearCollect(CurrentDataDb, First(NextDataDb2));
ClearCollect(AttemptedDataDb2, CurrentDataDb);
Remove(NextDataDb2,CurrentDataDb); 

next button onselect event

If(CountRows(NextDataDb2)>0,Patch(AttemptedDataDb2, First(CurrentDataDb),{UserChoice:Mid(Radio1.Selected.Value,1,1)});
ClearCollect(CurrentDataDb, First(NextDataDb2));
Collect(AttemptedDataDb2, CurrentDataDb);
Set(iRow,CountRows(AttemptedDataDb2));
Remove(NextDataDb2,CurrentDataDb))

Basically i am first identifying question collection and then use different collection to manipulate data without touching main collection. 

 

All Collections there after like currentdata or nextdata or attempteddata are manipulated there after.

 

I liked your idea of renaming columns. I will try this in future. Currently i dont see issue with column name. Issue is with collection name. PowerApps shows error in collection name when some elements in primary collection is added. Though i have been manually updating column names accross all related screen/button/onselect events but still error remains. Only option left for me is start renaming all collection names including all child collection names.

 

I believe there is something i might be doing wrong or there is some different way to handle such cases.

 

Just to add I have developed multiple powerapps apps. This collection issue is only with 1 app.

 

Thanks

Priyank

 

 

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 202 members 5,422 guests
Please welcome our newest community members: