Posts

Showing posts from 2017

SharePoint useful JavaScript objects, functions

There are several SharePoint inbuilt JavaScript objects / functions helps you to write script professional way and saves your time. The following are few you can explore more in SP.Init.debug.js and page sources. 1. _spPageContextInfo:   the object exists in sharePoint pages _spPageContextInfo.siteAbsoluteUrl:   returns the site collection url of the current web site. var siteUrl = _spPageContextInfo.siteAbsoluteUrl _spPageContextInfo.webAbsoluteUrl:   returns the current web site url. var webUrl = _spPageContextInfo.webAbsoluteUrl _spPageContextInfo.webServerRelativeUrl:   returns the current web relative url var webRelativeUrl = _spPageContextInfo.webServerRelativeUrl 2. SP.ScriptHelpers:   The function implemented in SP.Init.js and used across all scripts.  SP.ScriptHelpers.isNullOrEmptyString:   this method ensure the parameter is null or empty. var a; if(SP.ScriptHelpers.isNullOrEmptyString(a)) console.log(" empty "); else console.log("

Get Host site list items in SharePoint Hosted App.

Those who starts working on Apps might face issues to read host site list items. In sharepoint hosted APP using Rest API we able to query host site list items. The rest url to get host site is almost similar to get list items but we need to specify the app context and target. Make sure JQuery loaded before to execute the code in app web parts. 'use strict'; var HostUrl=""; var AppUrl==""; // load function // Intialize HostUrl, AppUrl from query strings. // call get items method $(document).ready(function () {         HostUrl= GetQueryString("SPHostUrl");        // Get Host Url from query string         AppUrl= GetQueryString("SPAppWebUrl");        // Get App Url from query string getItems("DemoList");                                        // get list items }); // function to get list items using Rest Api function getItems(listname) {             $.ajax({                 url: AppUrl + "/_