Page 1 of 1

Delete item button

Posted: 03 Aug 2018
by cmagnan
Hi,

I want to add a button to delete the item. I don't want to use the button in the toolbar.

Is it possible to achieved this?

Thanks
Catherine

Re: Delete item button

Posted: 06 Aug 2018
by Nikita Kurguzov
Dear cmagnan,
Please, use the following code in an OnClick property of a button:

Code: Select all

$( "a[aria-describedby='Ribbon.ListForm.Edit.Actions.DeleteItem_ToolTip']" )[0].click();
This will click the button in the Ribbon for you, essentially having the same effect as the Ribbon button.
DeleteItemButton.png
DeleteItemButton.png (38.44 KiB) Viewed 2806 times

Re: Delete item button

Posted: 22 Jan 2022
by picoso1986
Hello,
Does this code still work? I am using Sharepoint forms classic and it gives an error from Developer tools. Uncaught Type Error: Cannot read properties of undefined (reading 'click')

Re: Delete item button

Posted: 31 Jan 2022
by mnikitina
Hello picoso1986,

What SharePoint version are you using? Online or On-premises?

Re: Delete item button

Posted: 31 Jan 2022
by picoso1986
Hello,
Nikita has recommended a solution for this. I am using SharePoint On Prem 2016. The problem is that the customer wanted to disable the delete button by permissions so this affects the code on the button. He recommended to me the following:


"This code simply clicks the delete button, nothing else, it wouldn't work if the button is disabled. You have three options here:

1) Enable the Delete button, but hide it with CSS. Users still won't see the button, but you can run this script with no problem.

2) Write a custom JSOM or REST request to SharePoint, to find and delete item by ID. This will be harder, but should still be possible.

3) Add a field, maybe Yes/No field, something like MarkedToDelete. You can hide this field, and set the value with a script. Then, run a workflow on item update, and if MarkedToDelete is true, then delete the item. This requires extra steps, so it's not recommended, but possible. "

I posted here for anyone else running into this problem.

Thank you Margarita!