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
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PWREduCon768x460.png

Join us at PWR EduCon - A Power Platform Conference

Learn from the top Power BI, Power Apps, Power Automate & Power Virtual Agents experts!

Top Solution Authors
Top Kudoed Authors
Users online (3,262)