I have a SharePoint with several calendars named for their store number, I also have a list named Store Addresses which has the store numbers and their addresses.
I am trying to display the address on the top of the calendar page along with the page name (e.g., Store 500 - 111 Main St). I figured out how to display the page name, but need help pulling in and displaying the address.
I am using JavaScript to achieve this.
Edit: With help from a coworker we created the following code. But when we run it, it comes up with the error alert.
<script language="JavaScript">
var storeNumber = document.getElementsByTagName("title")[0].innerHTML;
var fieldValue = "";
storeNumber = storeNumber.split("-")[0];
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {
loadSharepointList();
});
function loadSharepointList() {
var context = SP.ClientContext.get_current();
var list = context.get_web().get_lists().getByTitle('storeAddresses');
var caml = new SP.CamlQuery();
caml.set_viewXml(
'<View><Query><Where><Eq>' +
'<FieldRef Name=\'Title\'/><Value>'+storeNumber+'</Value>' +
'</Eq></Where></Query></View>');
var listItems = list.getItems(caml);
context.load(listItems , 'Include(address)');
context.executeQueryAsync(
Function.createDelegate(this, function() {
fieldValue = listItems.get_item('address');
}),
Function.createDelegate(this, function() {
alert('Error fetching data from Sharepoint!');
}));
document.getElementById("testDiv").innerHTML = (storeNumber + "-" + fieldValue);}
</script>