Hide "Add New Item" link from sharepoint list view if user has already added an item.

Hide "Add New Item" link from sharepoint list view if user has already aaded an item
Descibes a javascript method to hide "Add New Item" link from sharepoint list view if user has already aaded an item. i.e. Allowing users to add only one item to the list  from Out Of Box (OOB) view or webpart.

Edit the view page and insert a Content Editor WebPart.

in the HTML of the content editor webPart put the following style and javascript along with the reference of JQuey.


<style>
    .ms-addnew
    {
        display: none;
    }
</style>
<script src="../../_layouts/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">

    var ListName = "MyList";


    $(document).ready(function () {
        ExecuteOrDelayUntilScriptLoaded(HideControl, "sp.js");
    });
    var myItems;
    function HideControl() {
        $('#Ribbon\\.ListItem\\.New').css('display', 'none');
        var currentContext = new SP.ClientContext.get_current();
        var currentWeb = currentContext.get_web();
        var todoTaskList = currentWeb.get_lists().getByTitle(ListName);
        var myQuery = new SP.CamlQuery();
        myQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name="Author" /> <Value Type="Integer"><UserID Type="Integer"/></Value></Eq></Where></Query></View>');
        myItems = todoTaskList.getItems(myQuery);

        currentContext.load(myItems, 'Include(ID)');
        currentContext.executeQueryAsync(Function.createDelegate(this, GetSuccess),
            Function.createDelegate(this, GetFail));

    }
    function GetFail(sender, args) {

    }

    function GetSuccess(sender, args) {
        var itemCount = myItems.get_count();
        if (itemCount == null || itemCount <= 0) {
            $('.ms-addnew').css('display', 'inline-block');
            $('#Ribbon\\.ListItem\\.New').css('display', 'inline-block');
        }
    }
    
</script>

* Change the  ListName = "MyList"; as per your list name.

That all.you can verify it by adding items through ribbon OR "add new item link" . you will notice that both the links are invisible it the item is added successfully and if you delete the item both the links are again available for adding new item to the list

Comments

  1. A website is an exceptional method for speaking with the world. onohosting.com/

    ReplyDelete
  2. The distribution of video games with out an age rating is punishable by imprisonment for as much as} five years or a fantastic. Among the video games rejected for recreation rankings, speculative video games account for the largest portion. Min K.R., Kyo J.K., Sun J.K. Psychosocial traits of web gamblers in South Korea. Among other issues, guests will discover a daily dose 룰렛 of articles with the newest poker information, stay reporting from tournaments, unique movies, podcasts, reviews and bonuses and a lot extra. According to a report from Transparency Market Research, the worldwide social gaming market is predicted to reach a price of $17.four billion by 2019. The GIPA is Korea's attempt to control what is usually expected to turn into one of many fastest-growing markets throughout the gaming business.

    ReplyDelete
  3. The best UK 카지노 casinos providing on-line or in-person gambling embrace dozens, if not hundreds, of slot video games. Registered gamers also receive daily kickers, which assist them earn extra rewards and improve in degree the extra they play. Unlocking ranges means extra bonus spins for video games and the OJO Wheel, properly as|in addition to} money prizes and extra. A lot of casinos will provide you with|provides you with} the option to play in demo mode. This is a wonderful way to try out the video games earlier than you make investments actual cash.

    ReplyDelete

Post a Comment

Popular posts from this blog

How to Build Mobile Apps for Online Marketplaces

The Growing Importance of Website Accessibility in the Digital Age

How to Choose the Right Software Development Company in 2023