Question

The Article page has a lot of properties that might be useful to read on the main page and not as a 'property' of the page only. Is there a code to occasionally surface any value (contact, Modified, etc) on the page in a text box? something easy that you can put in a script editor just on the pages you need and with the column field you need from that very page. I do not want a code for the master page.

Was it helpful?

Solution

By using _spPageContextInfo.pageItemId you query field values of page item (article page) and once you get the value you can bind it to any control you want on the page.

Value of Title :<label id="lbltipAddedComment"></label> <br/> 
Value of OtherColumn : <label id="lbltipAddedComment1"></label> 
    <script type="text/javascript">
    SP.SOD.executeFunc('sp.js','SP.ClientContext',getPageProperties);
    var item = "";

    function getPageProperties()
    {
        var context = new SP.ClientContext(_spPageContextInfo.webServerRelativeUrl);
        var list = context.get_web().get_lists().getById(_spPageContextInfo.pageListId);
        item = list.getItemById(_spPageContextInfo.pageItemId)
        context.load(item, "Title", "Test");
        context.executeQueryAsync(mySuccessFunction,myErrorFunction);
    }

    function mySuccessFunction()
    {
        var itemTitle = item.get_item("Title");
        var itemTest= item.get_item("Test");
document.getElementById('lbltipAddedComment').innerHTML = itemTitle ;
document.getElementById('lbltipAddedComment1').innerHTML = itemTest;
    }

    function myErrorFunction()
    {
        alert("F");
    }
    </script>
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top