1

I am looping through my list and would like to output the created date insted of ID in a div. Is it possible?

while (Enumerator.moveNext()) {
    var currentItem = Enumerator.get_current();

    lstString += "<br/>" + currentItem.get_item("ID");
}

$("#items").html(lstString);
2
  • Can you please share your code? You must be using JSOM Correct?
    – Asad Refai
    Commented Sep 9, 2015 at 12:42
  • You can update your question with code, rather than posting as an answer.
    – Asad Refai
    Commented Sep 9, 2015 at 12:52

3 Answers 3

3

Assuming you are using JSOM. The created date of a list item is stored in SharePoint's OOB field Created

Considering you have written the function to query list, this is the success call back function where we get values of an item.

function onQuerySucceeded(sender, args) {

    var listItemInfo = '';

    var listItemEnumerator = collListItem.getEnumerator();

    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        var CreatedDate = oListItem.get_item('Created');

    }

    alert(listItemInfo.toString());
}
1

I mostly get list item values like that:

<script type="text/javascript">

        $(document).ready(function() {    
            // Rest Call
            var requestUri = "/_api/lists/getbytitle('News')/items"; // My list is called News

                $.ajax({
                    url: requestUri,
                    type: "GET",
                    headers: { "ACCEPT": "application/json;odata=verbose" },
                    success: function (data) {
                        $.each(data.d.results, function (i, item){
                            var created = item.Created;

                            document.getElementById("head0").innerHTML = created;

                        })
                    },
                    error: function () {
                        alert("Error getting items");
                    }                     
                });   

        });
</script>

<!-- News -->
    <div class="col-md-9">
            <div id="head0"></div>
    </div>
<!-- /News -->

If this helps you, please give it a "vote up" or mark it as the answer.

0

Insted of ID i would like to get created date of a list item.I dont know if it is possible.

while (Enumerator.moveNext()) {
    var currentItem = Enumerator.get_current();

    lstString += "<br/>" + currentItem.get_item("ID");
}

$("#items").html(lstString);

}

Your Answer

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

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