Delete item button
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Dear cmagnan,
Please, use the following code in an OnClick property of a button:
This will click the button in the Ribbon for you, essentially having the same effect as the Ribbon button.
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();
Cheers
-
- Posts: 2
- Joined: Sat Jan 22, 2022
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')
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')
-
- Posts: 2
- Joined: Sat Jan 22, 2022
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!
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!
-
- Information
-
Who is online
Users browsing this forum: No registered users and 12 guests