I have a list with two columns, Title which it a single line of text and Hits which is a numbers column. What I’m trying to do is get to increment the Hits column whenever that item is viewed in the Display Form of the same list.
I’m Trying to do this with Java Script in a Content Editor on the display form, my knowledge of Java script is very limited, here is what I have so far using some example code provided to me. also the list is called Test HC 1.
<script src="/SiteAssets/JQuery/jquery-dateFormat.min.js" type="text/javascript"></script><script> function getListItems(){ alert('Test 1'); $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Test HC 1')/items?$select=ID,Title,Hits", method: GET Headers: Authorization: "Bearer " + accessToken accept: "application/json;odata=verbose" or "application/atom+xml" type: "GET", headers: {"accept": "application/json;odata=verbose","content-type": "application/json;odata=verbose", }, success: onSucceeded, error: onFailed }); } function onSucceeded(data) { alert('Test 2'); } function onFailed() { alert('Test 3');
} ExecuteOrDelayUntilScriptLoaded(getListItems, "sp.js");</script>
What I was trying to do was get the list items Title and Hits, this is what I was trying to do with the above code. This is as fare as I’ve gotten in my code, but its not working at the moment.
Then after that I was going to have it find the item with the same Title as the Display Form. One it did that have it increment the Hits +1. As of right now I can’t even get the alerts to pop up.