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.

View solution in original post

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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,918)