0

I have a div with a link to an item which is in a sharepoint list, but I need to show also the last time it was modified that report.

<div id="report">
   <h2>Title</h2>
   <a href="here's_the_link_to_the_item_in_the_sharepoint_list">Link to the report</a>
   <h5>Report last Update: (??)</h5>
</div>

The list has the column "Modified", but how can I make that info appears after "Report last Update:", so everytime someone modifies that item the date changes automatically in the HTML?
I know I can show these values with REST API, but I don't know how.

1

You need to supply more info on were this is being done (SharePoint custom form, SharePoint Designer edit, SharePoint App, external application, etc.), and how you are doing this (JavaScript, C#, etc.).

The REST might look like this:

https://yourServer/sites/yourSite/_api/web/lists/getbytitle('Announcements')/items?$filter=Id eq 10&$select=Modified

If using jQuery and AJAX, the call might look like this:

$.ajax(
{
    "url": "https://yourServer/sites/yourSite/_api/web/lists/getbytitle('Announcements')/items?$filter=Id eq 10&$select=Modified",
    "method": "GET",
    "headers": {
        "accept": "application/json; odata=nometadata"
    },
    "success" : successfunction,
    "error" : errorfunction
}
);

The exact URL will depend on where your code is running. If this is an external appication, you will need to deal with authentication. Depending on the SharePoint version, you may need "verbose" in place of "nometadata". Your "successfunction" will the place the data in the H5 tag.

More info...

Change your H5 to include an ID:

<h5 ID="ReportLastUpdate">Report last Update: </h5>

In the sample above change "successfunction" to: (the exact code will depend on the use of "nometadata" or "verbose".)

function(data){ $("#ReportLastUpdate").html(data.value[0].Modified) }

and the "errorfunction" to something like this:

function(err){ alert("ERROR: " + JSON.stringify(err, undefined, 4) + ) }
  • Is Sharepoint custom form, and I'm doing it with Javascript. But I'm really new with this, I don't know anything about REST API, so I'd like to know how to pass the info to the HTML. I can paste that code in my <script> (with some changes) but what do I put it in <h5>Report last Update: </h5> ? – Soul Eeater Jul 5 '18 at 18:16
  • Do you know JavaScript and jQuery? Is jQuery already loaded in the page? I've added a few more notes to the answer, but you will need to know some JavaScript basics. – Mike Smith - MCT - MVP Jul 5 '18 at 20:04
  • Thanks, I do know Javascript and Jquery. I was having trouble with some code that has nohing to do with this, but it already worked! – Soul Eeater Jul 10 '18 at 21:25

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.