0

I don't even know what this would be called, so I've having trouble googling it. I have a list that generates a single number based off some safety statistics: How many days since the last work accident. I would like to publish this number on the Home page. Can anyone suggest a way to do this? Or tell me where to look or what this would be called? Thanks

1

We can use REST API and jQuery Ajax to achieve it. Modify the code below and add it to script editor web part in the home page.

<script src="//code.jquery.com/jquery-3.2.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
    var url = _spPageContextInfo.webAbsoluteUrl;

    //add list name here
    var listName="Minor Incidents and Unsafe Conditions";

    //add the item id here
    var itemId=1;

    //add field name here
    var fieldName="DaysSinceLastMI";

    var requestUri = url + "/_api/web/lists/getbytitle('"+listName+"')/items("+itemId+")";
    $.ajax({
        url: requestUri,
        type: "GET",
        headers: { "ACCEPT": "application/json;odata=verbose" },
        success: function (data) {

            $("#NumberField").html("<span style='font-weight:bold;color:red;'>"+data.d[fieldName]+"</span>");
        },
        error: function (err) {
            //alert(err);
        }
    });
});
</script>
<div id="NumberField"></div>
  • Thanks. I'm not familiar with jquery. Can you tell me exactly where to put my List Name and List ID? The list name is "Minor%20Incidents%20and%20Unsafe%20Conditions" and the field in the list is called "DaysSinceLastMI". – PMartensen Dec 14 '17 at 15:41
  • I modify the code above and add some comments. – LZ_MSFT Dec 15 '17 at 1:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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