cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JomarGF
Helper III
Helper III

Please help spot the error

Hi All

 

Please help me spot the error in the following code:

 

If(
CountIf(
collDefectsList,
fkAssetID = iAssetID,
fkDefectID = ThisItem.DefectID
) > 0,
Patch(
collDefectsList,
LookUp(
collDefectsList,
fkAssetID = iAssetID && fkDefectID = ThisItem.DefectID
),
{
DTStamp: Now(),
fkAssetID: iAssetID,
fkDefectID: ThisItem.DefectID
}
),
Patch(
collDefectsList,
Defaults(collDefectsList),
{
DTStamp: Now(),
fkAssetID: iAssetID,
fkDefectID: ThisItem.DefectID
}
)
);

 

Thank you in advance!

1 ACCEPTED SOLUTION

Accepted Solutions

Hi CNT

 

Not yet. I think I need to rethink my approach. Maybe not start with CountIf? What I am trying to do is check if a record exist in the collection with the argument fkAssetID and fkDefectID.

 

If it does, I would update that record, if not add new.

 

What if I just delete the record and add my new value each time an update or add new is triggered?

 

Have a great day!

 

Jomar

View solution in original post

18 REPLIES 18
JomarGF
Helper III
Helper III

The error starts with Patch...

CNT
Super User
Super User

@JomarGF what is the error? 

Red line from Patch to end of the code. Saying Patch has invalid arguments?

 

  

@JomarGF you're using ThisItem.DefectID

What is ThisItem referring to? 

Hi CNT

 

ThisItem.DefectID is from the gallery where I select the defect desc + defectID. I tried taking out ThisItem.DefectID and the issue persists. 😞 

@JomarGF In the If you have 2 Patch statements ( 1 in the If part and the other in the else part). To isolate the error could you just remove one and see which Patch has the problem.

Hi CNT

 

Thank you for your reply.

 

I took out the values inside the brackets and the redline disappears! (see screenshot). What do you think is the issue?

 

Capture.JPG

Hi CNT

 

Does Patch work for Collections???

 

Thank you.

@JomarGF Are the datatypes of fkAssetID & fkDefectID matching with iAssetID & ThisItem.DefectID.

Did you try to hardcode some value and see?

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (3,003)