0

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>
0

You could use SharePoint rest api to get the list items in Store Addresses, then display the page name and address by jQuery.

Sample rest api demo from this thread.

function retriveListItem()  
{  

    $.ajax  
    ({  
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('companyInfo')/items?$select=Company,Industry",  
        type: type,  
        data: data,  
        headers:  
        {  
            "Accept": "application/json;odata=verbose",  
            "Content-Type": "application/json;odata=verbose",  
            "X-RequestDigest": $("#__REQUESTDIGEST").val(),  
            "IF-MATCH": "*",  
            "X-HTTP-Method": null  
        },  
        cache: false,  
        success: function(data)   
        {  
            $("#ResultDiv").empty();  
            for (var i = 0; i < data.d.results.length; i++)   
            {  
                var item = data.d.results[i];  
                $("#ResultDiv").append(item.Company + "\t" + item.Industry + "<br/>");  
            }  
        },  
        error: function(data)  
        {  
            $("#ResultDiv").empty().text(data.responseJSON.error);  
        }  
    });  
} 

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.