0

I would like to have an edit button (not in ribbon) to show when a Sharepoint list item is viewed/display, with condition Where field "Status" is not equal to "Approved". Can somebody lend a hand on this?

1 Answer 1

0

Sample code with CSR,insert script editor webpart to list form and insert the script(update the list form URL to your own).

<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script>
(function () {
    'use strict';

    var CustomCtx = {};

    /**
     * Initialization
     */
    function init() {

        CustomCtx.OnPostRender = customDisplay;       

        // Register the custom template
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides(CustomCtx);
    }

    /**
     * Rendering template
     */
    function customDisplay(ctx) {
        window.PostRunCheck;
        if(!window.PostRunCheck){
            var currentStatus = ctx.ListData.Items[0].Status;
            var currentItemID=parseInt(getQueryStringParameter('ID'));
            var htmlEdit = "<a href='/Lists/Tasks/EditForm.aspx?ID={{ID}}'>Edit</a><br/>";
            if (currentStatus != "Approved"){
                $('table.ms-formtable').parent().prepend(htmlEdit.replace('{{ID}}',currentItemID));
            }
            window.PostRunCheck=true;
        }

    }
    function getQueryStringParameter(paramToRetrieve) {
            var params = document.URL.split("?")[1].split("&");
            for (var i = 0; i < params.length; i = i + 1) {
                var singleParam = params[i].split("=");
                if (singleParam[0] == paramToRetrieve) return singleParam[1];
            }
        }   
    // Run our intiialization
    init();

})();</script>

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.