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!

18 REPLIES 18

@JomarGF For sure they do.

I tried that. See screenshot... This is getting interesting...Capture.JPG

 

@JomarGF OK. Replace the LookUp with First(collDefectsList). Let's see what happens.

Hi CNT

 

Looks like LookUp is the culprit. see screenshot.Capture.JPG

@JomarGF Glad we narrowed it down. Check the LookUp separately and let me know what happens 

CNT
Super User
Super User

@JomarGF Did you fix it?

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

Hey, thank you for your assistance.

 

Apologies for only getting back to you. I am based in Sydney and our time difference might be huge. 🙂

 

As I mentioned, I will stick to delete then add solution for the moment. It would have the same effect as I am trying to achieve with less code. 🙂

 

Jomar

@JomarGF That's great! Glad to help you along the way!

 

Please remember to give a 👍 and accept the solution as it will help others in the future.

Helpful resources

Announcements
User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

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