none
Capturing delete event using custom js RRS feed

  • Question

  • Hi All,

    I have following custom js code to capture delete event on library item 

    Once user clicks on ... hover menu for item opens and has ... to capture click of ... hover I have 

    $(".js-callout-action.ms-calloutLinkEnabled.ms-calloutLink.js-ellipsis25-a").click(function() {
        console.log("... on hover clicked);
    });

    The menu then shows me Delete option and to capture delete event I have following code :

    $("#ID_DeleteDocItem").click(function() {
                console.log("delete called");
          });

    But the issue delete is clicked, sharepoint has a alert - Are you sure you want send items to Recycle bin? with OK and Cancel button, and this is the issue I am unable to capture the alert and button click on OK or Cancel 

    I want to call a custom function on click of Delete file

     

    Thanks in Advance, Jiniv Thakkar

    Monday, November 25, 2019 8:15 PM

Answers

  • Hi,

    Check below function for document library item.


    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by Jiniv Thakkar Tuesday, November 26, 2019 8:19 AM
    Tuesday, November 26, 2019 7:26 AM

All replies

  • Hi ,

    You could try to override default delete function.

    https://social.msdn.microsoft.com/Forums/office/en-US/02ddc0a4-92b8-4281-81fd-f80a8e8963df/custom-message-while-item-deleting-within-list-with-yes-and-cancel-option-to-proceed-or-not-to?forum=sharepointdevelopment#9511261e-db78-4610-89de-d4a470b8481c

    You could find the source script in below file.


    Override JavaScript function.

    https://stackoverflow.com/questions/5409428/how-to-override-a-javascript-function

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, November 26, 2019 1:41 AM
  • Hi Lee,

    I tried the following code and it works but this code is for list item, I want this solution to work for library files/items

    <script type="text/javascript">
            SP.SOD.executeOrDelayUntilScriptLoaded(CustomJS, 'Core.js');
            
            function CustomJS() {
                var _DeleteListItem = window.DeleteListItem;
                window.DeleteListItem = function DeleteListItem() {
                    if (!IsContextSet())
                        return;
                    var ctxt = currentCtx;
                    var ciid = currentItemID;
                    var strMessage = "this item will be deleted permanently from another systems too, do you still want to continue?"; //Strings.STS.L_STSRecycleConfirm_Text;
    
                    if (!ctxt.RecycleBinEnabled || ctxt.ExternalDataList)
                        strMessage = Strings.STS.L_STSDelConfirm_Text;
                    if (Boolean(ctxt.HasRelatedCascadeLists) && ctxt.CascadeDeleteWarningMessage != null)
                        strMessage = ctxt.CascadeDeleteWarningMessage + strMessage;
                    if (confirm(strMessage)) {
                        var noti = Strings.STS.L_Notification_Delete;
                        var nid = addNotification(noti, true);
                        var clvp = ctxt.clvp;
    
                        if (ctxt.ExternalDataList && clvp != null) {
                            clvp.DeleteItemCore(ciid);
                            clvp.pendingItems = [];
                            if (typeof clvp.cctx.executeQueryAsync != "undefined")
                                clvp.cctx.executeQueryAsync(function () {
                                    if (clvp.rgehs != null && typeof clvp.rgehs.length == "number") {
                                        if (clvp.rgehs.length == 1 && clvp.rgehs[0].get_serverErrorCode() == SP.ClientErrorCodes.redirect) {
                                            GoToPage(clvp.rgehs[0].get_serverErrorValue());
                                            return;
                                        }
                                        removeNotification(nid);
                                        clvp.ShowErrorDialog(RefreshOnDialogClose);
                                    }
                                    else
                                        RefreshPage(SP.UI.DialogResult.OK);
                                }, function () {
                                    removeNotification(nid);
                                    if (typeof clvp.rgehs != "undefined")
                                        clvp.ShowErrorDialog(function () {
                                        });
                                });
                        }
                        else {
                            var urlToPost = ctxt.HttpPath + "&Cmd=Delete&List=" + ctxt.listName + "&ID=" + ciid + "&NextUsing=" + GetSource();
    
                            if (null != currentItemContentTypeId)
                                urlToPost += "&ContentTypeId=" + currentItemContentTypeId;
                            SubmitFormPost(urlToPost);
                        }
                    }
                };
            }       
        </script>



    Thanks in Advance, Jiniv Thakkar

    Tuesday, November 26, 2019 6:46 AM
  • Hi,

    Check below function for document library item.


    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by Jiniv Thakkar Tuesday, November 26, 2019 8:19 AM
    Tuesday, November 26, 2019 7:26 AM
  • Here's my code 

    SP.SOD.executeOrDelayUntilScriptLoaded(CustomJS, 'Core.js');
            
            function CustomJS() {
                var _DeleteDocLibItem = window.DeleteDocLibItem;
                window.DeleteDocLibItem = function DeleteDocLibItem() {
                    if (!IsContextSet())
                        return;
                    var ctxt = currentCtx;
                    var ciid = currentItemID;
                    var strMessage = "this item will be deleted permanently from another systems too, do you still want to continue?"; //Strings.STS.L_STSRecycleConfirm_Text;
    
                    if (!ctxt.RecycleBinEnabled || ctxt.ExternalDataList)
                        strMessage = Strings.STS.L_STSDelConfirm_Text;
                    if (Boolean(ctxt.HasRelatedCascadeLists) && ctxt.CascadeDeleteWarningMessage != null)
                        strMessage = ctxt.CascadeDeleteWarningMessage + strMessage;
                    if (confirm(strMessage)) {
                        var noti = Strings.STS.L_Notification_Delete;
                        var nid = addNotification(noti, true);
                        var clvp = ctxt.clvp;
    
                        if (ctxt.ExternalDataList && clvp != null) {
                            clvp.DeleteItemCore(ciid);
                            clvp.pendingItems = [];
                            if (typeof clvp.cctx.executeQueryAsync != "undefined")
                                clvp.cctx.executeQueryAsync(function () {
                                    if (clvp.rgehs != null && typeof clvp.rgehs.length == "number") {
                                        if (clvp.rgehs.length == 1 && clvp.rgehs[0].get_serverErrorCode() == SP.ClientErrorCodes.redirect) {
                                            GoToPage(clvp.rgehs[0].get_serverErrorValue());
                                            return;
                                        }
                                        removeNotification(nid);
                                        clvp.ShowErrorDialog(RefreshOnDialogClose);
                                    }
                                    else
                                        RefreshPage(SP.UI.DialogResult.OK);
                                }, function () {
                                    removeNotification(nid);
                                    if (typeof clvp.rgehs != "undefined")
                                        clvp.ShowErrorDialog(function () {
                                        });
                                });
                        }
                        else {
                            var urlToPost = ctxt.HttpPath + "&Cmd=Delete&List=" + ctxt.listName + "&ID=" + ciid + "&NextUsing=" + GetSource();
    
                            if (null != currentItemContentTypeId)
                                urlToPost += "&ContentTypeId=" + currentItemContentTypeId;
                            SubmitFormPost(urlToPost);
                        }
                    }
                };
            }


    Thanks in Advance, Jiniv Thakkar

    Tuesday, November 26, 2019 8:21 AM
  • How can I capture Edit properties click event ? What is the function name associated with Edit properties ?

    How can I see the core.debug.js?


    Thanks in Advance, Jiniv Thakkar

    Tuesday, December 10, 2019 6:27 AM
  • Hi

    You could get the debug version in layouts folder.


    For document library, ‘Edit properties’ will call below function(click the red part will format the js as below).


    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, December 10, 2019 8:38 AM
  • Thanks but I am working on SharePoint online, so dont have access to the files directly

    _EditItemWithCheckoutAlert is also called for Edit of file properties ?


    Thanks in Advance, Jiniv Thakkar


    Tuesday, December 10, 2019 8:45 AM
  • Hi

    Confirmed in my SharePoint online.

    You could click the red part command to get the source code.

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, December 10, 2019 8:56 AM