0

I have a filter list, where I select a specific list-item on the displayed list. There are 8 fields that I need to retrieve and load onto html boxes. The user can edit some of these returned values. I then need to populate the values for the Document Library Form from these text boxes. Question: How do I do this with code? I am new to jquery, so a code sample would be really helpful, including all initialisations?

1 Answer 1

0

You can use REST API to get the list items and populate the values in the document library form. There is a code sample below.

     <div>  
    <p>  
        <b>List Items</b>  
        <br />  
        <select style="height:400px; width:200px" multiple="multiple" id="selectalllistitems"></select>  
    </p>    
</div> 
<script type="text/javascript">
    $(function () {
        $.ajax({
            url: "https://testlz.sharepoint.com/sites/wendy2/_api/web/lists/GetByTitle('clist2')/items",
            type: 'GET',
            headers: {
                                    accept: "application/json;odata=verbose"
            },
            success: successHandler,
            error: errorHandler
        })
    })
    function successHandler(data, textStatus, jqXHR) {
        alert("successHandler " + "textstatus:" + textStatus + "data: " + data);


var selectallitems = document.getElementById("selectalllistitems");  
if (selectallitems.hasChildNodes())  
{  
    while (selectallitems.childNodes.length >= 1)   
    {  
        selectallitems.removeChild(selectallitems.firstChild);  
    }  
}  
var display = data.d.results;  
for (var i = 0; i < display.length; i++)  
{  
    var selectitems = document.createElement("option");  
    selectitems.value = display[i].Title;  
    selectitems.innerText = display[i].Title;  
    selectallitems.appendChild(selectitems);  
}  

    }

    function errorHandler(xhr, ajaxOptions, thrownError) {
        alert('Request failed: ' + xhr.status + '\n' + thrownError + '\n' + xhr.responseText);
    }
</script>

More reference:

Working with lists and list items with REST.

https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-lists-and-list-items-with-rest

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.