0

I have list with two columns, like group and users, while adding item to list am showing existing Groups in list new item form. the Group field is not unique. here my requirement is i want show distinct group names in New item form instead of duplicate.

thank you in advance.

  • Are you using Group field as Single Line of Text OR Choice where users allowed to add their own entry in dropdown? Also are you showing the existing values in DropDown in a custom New Item Form? – Yayati Sep 20 '17 at 13:37
  • Its a single line of text. – rajendar Sep 21 '17 at 4:58
1

You Can do group by to get the distinct value. You cannot keep directly group by option in REST API URL so you can keep CAML query in REST API, In CAML query you can use GROUP By option.

You can see this post for REST API with CAML http://www.c-sharpcorner.com/blogs/sharepoint-rest-api-caml-query

You can use U2U tool for CAML query builder for Group By option

1

As per your requirment, you need show list of existing group names as suggestion in the NewItemForm page of that list. To achieve this you can use jQuery UI AutoComplete feature.

It will show list of unique groups in a dropdown list which user can either select a value from the list OR they can enter their own value in the textbox.

Hope this is what you want to acheive.

Following is code snippet which you have to include inside a content editor web part on that page.

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js "></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>

<script type="text/javascript">
    $(document).ready(function () {
        SP.SOD.executeOrDelayUntilScriptLoaded(init, "sp.js");
    });
    function init(){
        $.ajax( {
            method: 'GET',
            url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('myListName')/items?$select=Title",
            contentType: "application/json; odata=verbose",
            headers: {
                "Accept": "application/json; odata=verbose"
            },
            success: function( data ) {
                var arr = [];
                for(var i = 0; i < data.d.results.length; i++){
                    arr.push(data.d.results[i].Title);
                }
                arr = $.unique(arr); // returns array with unique values
                $("input[type=text][title='Title']").autocomplete({
                    source: arr,
                    minLength:0
                }).focus(function(){
                    $(this).data("uiAutocomplete").search($(this).val());
                });
            },
            error: function(e){
                console.log("Error");
                console.log(e);
            },
        });
    }
</script>

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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