I am looking at trying to run some code against a list object when a user is viewing it. (for example, when a user views an item to, on load, updating the item with a 'has been viewed' field to 'true')
My thought process is to run a piece of javasript to somehow, when the page loads with the item, to find the current item ID. Then, by using some other piece of code, to update the field automatically and save it.
I am just unsure how to effectively get the item ID using JS (Im relatively new to both SP and JS)
From what I can tell, the ID is in the url (in this case, it's '58') -
.../NewDisplayForm.aspx?ID=58&Source=...
What would be a suitable peice of JS to get this value when the page loads, and out of interest, what would be the suggested way to then programatically update the object field and save it?
thanks!
I'm trying to run `console.log(_spPageContextInfo.pageItemId)' but it seems like, in my case, there is no PageItemId property available to me. (I am running this in my debug console while viewing a list item).
Regarding the issues you raised, the page wont be in 'edit' mode but in display mode. Will this be a problem still? Also the website/portal wont be used by more than 2-3 people concurrently.
– Simon May 07 '15 at 07:47If you need to track how different users have read the generated email list item, and if you would store that information on the item, you would still need to edit the item programmatically and may run into issues I listed above.
– Jussi Palo May 07 '15 at 10:19