locked
Hide the "Edit Item" from the tool bar in the dispform.aspx based on the status of that item RRS feed

  • Question

  • Hi Everybody,

                       I am struggling with hiding/removing the "Edit Item" from the toolbar in a dispform.aspx. In  my scenario, based on the status of that item (completed, in progress..) i have to hide the edit item option from the dispform.aspx e.g. if the item is in completed stage then any one should not edit that item.

    Any help would be heartfully appreciated. We are not allowed to use SPD and we can't modify core.jss or any other pages.


    Radhika
    Monday, March 7, 2011 4:20 AM

Answers

  • Hi Pman,

    Thanks for your reply..it was really useful.. and also from your post i got an idea which helped me to acheive my functionality.. :) 

     and thanks everybody for replying.

    I have followed this approach. And its working for me.. :)

    1. Added a CEWP in the EditForm.aspx

    2. Added a javascript which will read the "Status" value, current item id (from the query string) and if its completed then it redirects the user to the DispForm.aspx?ID=currentlistitemID (which we read from the query string). This is the full code

    <script type="text/javascript">

     

       window.onload = function()

       {

     

        var param = getUrlParam("ID");

        var tagName = "select";

        var identifier = "";

        var title = "Status";

        var complete = "Completed";

     

       var len = identifier.length;

       var tags = document.getElementsByTagName(tagName);

       for (var i=0; i < tags.length; i++) {

       var tempString = tags[i].id;

       if (tags[i].title == title && (identifier == "" ||  tempString.indexOf(identifier) == tempString.length - len)) {

     if(tags[i].value == complete)

       {

          window.navigate("DispForm.aspx?ID=" + param)        }

          return tags[i];

        }

      }

      return null;

    }

     

    function getUrlParam(param)

    {  

    param = param.replace(/([\[\](){}*?+^$.\\|])/g, "\\$1");  

    var regex = new RegExp("[?&]" + param + "=([^&#]*)");  

    var url   = decodeURIComponent(window.location.href);  

    var match = regex.exec(url);   return match ? match[1] : "";

     }

     

    </script>

     

    3. By using the above code i acheived my functionality because no one can go to the "EditForm.aspx" page if that particular item's status is "Completed"

    For me its working like a charm.. :)

    Regards,

    Radhika

     

     


    Radhika
    • Marked as answer by SP-User Monday, March 14, 2011 9:53 AM
    Monday, March 14, 2011 9:52 AM

All replies

  • > We are not allowed to use SPD

    This always amazes me.

    SPD 2007 was a commercial product that became free because Microsoft realised that it was an essential tool for maintaining SharePoint 2007 sites.

    Whereas I can understand that a company can ban the use of free unsupported tools from private people, I do not understand how companies can ban the use of mainstream *commercial* tools from the manufacturer of the product they are using.

    Yes, care should be taken when using SPD 2007 so that master pages (etc.) are not destroyed, but care must be taken with most computer systems so this should be no reason for not using SPD 2007 at all.

    (You can use the above text if you require reasons for getting the company to allow use of SPD 2007!)

    Moderator (non-Microsoft)


    SP 2010 "FAQ" (mainly useful links): http://wssv4faq.mindsharp.com/default.aspx
    WSS3/MOSS FAQ (FAQ and Links) http://wssv3faq.mindsharp.com/default.aspx
    Both also have links to extensive book lists and to (free) on-line chapters
    Monday, March 7, 2011 7:44 AM
  • I Second Mike on this. When you are working on custom development in SharePoint, you surely need a helpful tool like SharePoint Designer.
    Thanks,
    Chanakya
    Monday, March 7, 2011 9:12 AM
  • Thanks Mike for the reply. Will surely use the above text to allow us SPD07.

    But currectly we have to acheive this functionallity without using SPD or custom development. Pls help

    Thanks,


    Radhika
    Monday, March 7, 2011 10:43 AM
  • Hey Radhika,

    You'd definitely need "custom development/customization" but since you need to do it without using SPD, here's what you can do through browser:

    1. In your DispForm.aspx page, add a CEWP through the browser

    2. Enter JavaScript using the Source Editor of the CEWP. You can create your javascript using any other html editing tools and just copy it in the Source Editor of the CEWP

    3. Using JavaScript, check the value of the status field. If it's "Complete", hide the "Edit" button.

    4. Install the "IE Developer Tool" for your IE. It's an add-on for IE browser and will help you find out "id/class" of particular html nodes. You'll need them in your JavaScript code.

    Here's a link that you might find very useful. It's about manipulating sharepoint form fields using JavaScript:

    http://blogs.msdn.com/b/sharepointdesigner/archive/2007/06/13/using-javascript-to-manipulate-a-list-form-field.aspx

     

    That's just 50% of your work because hiding the "Edit" button from the DispForm page doesn't necessarily give you the security you're looking for. User's can click on "Edit" from the context menu on the item in list view or browse to the "EditForm.aspx" page directly to edit an item.

    The ideal solution probably would've been using a workflow (built using SPD) and remove edit permission from the user's on the particular list item. Since SPD is not an option, you'll need to include javascript on this "EditForm.aspx" page too and make sure you disable all the fields if the "Status" is "Complete"

    Hope that helps...

     


    Pman
    http://www.pmansLab.com/
    Wednesday, March 9, 2011 3:08 AM
  • Hi Radhika,

    You can break the list permission and assign the permissions to the special items. In this way, Edit Item option would be hidden.

    There is a solution named SharePoint workflow activities in codeplex allow us modify list item permissions in workflow, but you are not allow to use SharePoint Designer. Then you can create a VS workflow or using PowerShell instead.

    Here is a blog break the item permission in VS workflow.
    http://blogs.devhorizon.com/reza/?p=9

    And here is a similar thread, Joel have performed this function using PowerShell. Please take a look.
    http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/849f0a85-a42c-4d10-98d0-cd5ec8e5a3f2/

    Best regards,
    Emir

    Wednesday, March 9, 2011 6:29 AM
  • Hi Pman,

    Thanks for your reply..it was really useful.. and also from your post i got an idea which helped me to acheive my functionality.. :) 

     and thanks everybody for replying.

    I have followed this approach. And its working for me.. :)

    1. Added a CEWP in the EditForm.aspx

    2. Added a javascript which will read the "Status" value, current item id (from the query string) and if its completed then it redirects the user to the DispForm.aspx?ID=currentlistitemID (which we read from the query string). This is the full code

    <script type="text/javascript">

     

       window.onload = function()

       {

     

        var param = getUrlParam("ID");

        var tagName = "select";

        var identifier = "";

        var title = "Status";

        var complete = "Completed";

     

       var len = identifier.length;

       var tags = document.getElementsByTagName(tagName);

       for (var i=0; i < tags.length; i++) {

       var tempString = tags[i].id;

       if (tags[i].title == title && (identifier == "" ||  tempString.indexOf(identifier) == tempString.length - len)) {

     if(tags[i].value == complete)

       {

          window.navigate("DispForm.aspx?ID=" + param)        }

          return tags[i];

        }

      }

      return null;

    }

     

    function getUrlParam(param)

    {  

    param = param.replace(/([\[\](){}*?+^$.\\|])/g, "\\$1");  

    var regex = new RegExp("[?&]" + param + "=([^&#]*)");  

    var url   = decodeURIComponent(window.location.href);  

    var match = regex.exec(url);   return match ? match[1] : "";

     }

     

    </script>

     

    3. By using the above code i acheived my functionality because no one can go to the "EditForm.aspx" page if that particular item's status is "Completed"

    For me its working like a charm.. :)

    Regards,

    Radhika

     

     


    Radhika
    • Marked as answer by SP-User Monday, March 14, 2011 9:53 AM
    Monday, March 14, 2011 9:52 AM
  • I used SharePoint Manager 2007 to point the edit function of a list item (EditFormURL attribute) to the DispForm.aspx instead of the EditForm.aspx. Even if the user clicks the edit button on the form, it returns them to the DispForm.aspx. The only problem I am working on is how to hide the delete button. Probably use jquery to do that.

    Not sure if that would help you. Also, it would not allow anyone to edit a list item unless you switched the attribute back in SP Manager

    Friday, November 2, 2012 4:16 PM