We have a Job Opportunities list in SharePoint Online. I then have a JQuery script to rollup the list items on our homepage.

In SharePoint edit mode the code works fine but soon as the page is published it doesn't display. We have referenced the JQuery library in the master page. I run a basic hello world test and that worked when published so I suspect its the code. MDS is switched off on the page but we added

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', retrieveListItems);

to help with this.

Please could someone review the code and let me know why it might not be working? Any help would be most appreciated.


#divListItems {width: 320px; height: auto; background: #eeeeee; padding: 20px;}
.test {margin: 0px; font-family: arial; padding: 5px;}
<h1>People Opportunities</h1>
<div id="divListItems">
<script type="text/javascript">
$(function (){
function retrieveListItems() {
var clientContext = new SP.ClientContext();
var camlQuery = new SP.CamlQuery();
this.collListItem = oList.getItems(camlQuery);
Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed)
function onQuerySucceeded(sender,args) {
var listItemInfo ='';
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
listItemInfo + =
'<div class="test">' + oListItem.get_item('Title') + '</div>' 
listItemInfo += 
'<div class="test"><strong>Location:</strong>'+ oListItem.get_item('Location') + '</div>'
listItemInfo +=
'<div class="test"><strong>Recruiting Manager:</strong>'+ oListItem.get_item('RecruitingManager').get_lookupValue() + '</div>'
listItemInfo += 
'<div class="test"><strong>HR Contact:</strong>'+ oListItem.get_item('HRContact').get_lookupValue() + '</div>'
listItemInfo +=
'<div class="test"><strong>Closing Date:</strong>'+ oListItem.get_item('ClosingDate') + '</div><br>' 
'<br />';
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() +
'\n' + args.get_stackTrace());
  • Instead of image, can you paste the code here ? Will help us in debugging. Jul 12, 2017 at 16:13

2 Answers 2


I had the same problem with some code I added directly to the page.

My developer said that the code had to be added to the


folder to take affect after publishing.

Your /css folder may be in a different place.


You can also try using SP.SOD.executeOrDelayUntilScriptLoaded instead of SP.SOD.executeFunc. The key difference is explained here.

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.