cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ZStaniek
Regular Visitor

Error() is not raised after Remove()

If I go directly to SQL database and execute DELETE statement

DELETE FROM [dbo].[List]
WHERE ListID = '25'

I am getting an error message

Msg 547, Level 16, State 0, Line 4
The DELETE statement conflicted with the REFERENCE constraint "FK_ListMember_List". The conflict occurred in database "AxysImp", table "dbo.ListMember", column 'ListId'.

Which is a proper behavior since there is a foreign key constraint on ListMember table and ListMember table contains rows with ListId=25.

When I try to delete the same record from the SharePoint gallery using the following ON SELECT command:

Remove(
'[dbo].[List]',
ListGallery.Selected
);
Notify(Text(IsEmpty(Errors('[dbo].[List]'))))

the record does not get deleted, but the Errors collection remains empty, which means i am not notified about the error.

Please help.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

@ZStaniek ,

Try this

RemoveIf(
   '[dbo].[List]',
   ListID = ThisItem.ListID
   )
);
Notify(
   Text(
      IsEmpty(
         Errors(
            '[dbo].[List]',
            LookUp(
               '[dbo].[List]',
               ListID = ThisItem.ListID
            )
         )
      )
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

5 REPLIES 5
eka24
Super User
Super User

 

Is the remove botton inside the Gallery or Outside the Gallery. If Inside the Gallery, try:

Remove([dbo].[List],LookUp([dbo].[List],ID = ThisItem.ID))

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

 

ZStaniek
Regular Visitor

Yes, my button is within the gallery.

I have tried two versions:

 

Remove('[dbo].[List]',LookUp('[dbo].[List]',ListID = ThisItem.ListID));Notify(Text(IsEmpty(Errors('[dbo].[List]',LookUp('[dbo].[List]',ListID = ThisItem.ListID)))))

 

and

 

Remove('[dbo].[List]',LookUp('[dbo].[List]',ListID = ThisItem.ListID));Notify(Text(IsEmpty(Errors('[dbo].[List]'))))

 

Record does not get deleted (rightly so), but the Notify result is still true, which means no error was detected.

 

 

 

@ZStaniek ,

Try this

RemoveIf(
   '[dbo].[List]',
   ListID = ThisItem.ListID
   )
);
Notify(
   Text(
      IsEmpty(
         Errors(
            '[dbo].[List]',
            LookUp(
               '[dbo].[List]',
               ListID = ThisItem.ListID
            )
         )
      )
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Hello Warren,

 

I give you a credit for solving this. I came to the same conclusion yesterday and was about to post my solution, which is essentially the same. 

While there is a solution to the problem, the question remains, why Remove() does not handle errors properly and must be replaced with RemoveIf(). 

My solution:

RemoveIf(
'[dbo].[List]',
ListID = ThisItem.ListID
);
If(
!IsEmpty(
Errors(
'[dbo].[List]',
LookUp(
'[dbo].[List]',
ListID = ThisItem.ListID
)
)
),
Notify(
"Member items present, remove first",
NotificationType.Error
)
)

Thanks @ZStaniek ,

The post is also about other people finding it.

I always use RemoveIf as it always works - I guess I don't look for reasons why other things don't too much unless I need to use them.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

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.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (1,120)