Posts

Showing posts from April, 2016

How to get custom user profile property from SharePoint User Profile Service using JavaScript AJAX client side script

Image
Hi There, SharePoint provides a wonderful facility of client side scripts to get data from SharePoint objects. You can get custom user profile property from SharePoint User Profile Service using JavaScript AJAX calls. Below is an example. I have an AD property with name "Initials" that do not comes in SharePoint OOTB  User Profile Service and you have to bind it manually. I have set its internal name also "Initials" in my User Profile Service while binding it. We'll call this property using the same name. Remember that, you can only call a User Profile Property from its internal name. I have bonded it with "Initials" attribute of AD and set the Direction to Import . Click Add. Now the custom property is appearing when i edit any user profile. Below is my JavaScript code. [code]//Display User profile properties function getMyUserProfile(success, error) { var siteUrl = _spPageContextInfo.siteAbsoluteUrl;

SharePoint Client Side REST API 500 Internal Server Error

Image
Hi There, I have been now in code again since last two months and facing the developer life challenges :P . I am calling the GetMyProperties from client side REST API method  "/_api/SP.UserProfiles.PeopleManager/GetMyProperties" but my site is throwing 500 internal server error or 400 bad request . Life time annoying errors :-/ . My code was working fine on my dev machine but not on client's server, so apparently its a server configuration issue. Things to check when you get 500 Internal Server Error or similar IIS erros on " /_api/XXXXXXXXXXXXXXXX" or same kind of issues is,  1. Check your User Profile Service is running properly 2. Check your my site is configured properly 3. Check your my site is configured in my site host application in User Profile Service In my case, the issue was, my MySite was not configured in User Profile Service and when i open MySite it throws error and a correlation ID. So i added my MySite in User Profile

Traverse all users permissions on SharePoint 2010,2013 Site Collection PowerShell

Image
Hi There, I have found a very useful PowerShell script to traverse all users permissions on SharePoint 2010,2013 Site Collection using PowerShell. Thanks to Johan Mayer for updating the PowerShell code and making it more useful. This PowerShell code will traverse or extract all users having permissions through any of SharePoint group and any level of permission. For example, if a User has permissions using three groups Readers, Contributors and Owners, it will show all groups one by one and describe the user permissions level in each group. Sample screenshot below. PowerShell Script: You can copy and paste this PowerShell script in a simple notepad file and save as .ps1 file. Now run SharePoint Management Shell and point to the file where you have just saved. This script will traverse users permissions inside the lists/libraries too. You can filter the data once exported in CSV. function Get-SPUserEffectivePermissions ( [object[]] $users

SharePoint 2013 Blog Post Error : TypeError: Unable to get property 'id' of undefined or null reference

Image
Hi There, Its a brand new installation with no customization on SharePoint site. I created a blog type subsite called "News" in SharePoint and faced the below error. This error comes up when i created a blog post in SharePoint from User1 account and then open the same post with User2  account which had read only permissions on the site.  TypeError: Unable to get property 'id' of undefined or null reference OR TypeError: Unable to get property 'trim' of undefined or null reference My current version of SharePoint was RTM 15.0.4420.1017. I installed the SharePoint Server SP1 (15.0.4569.1000) and the error " TypeError: Unable to get property 'id' of undefined or null reference " went away. Mean while i tested the same thing on another RTM version of SharePoint where it worked fine without any issue and  installation  of SP1. Hope it will help someone...! Happy SharePointing...!

How to find city weather dynamically from Google map and Yahoo weather API with JavaScript

Hi There, If you have read my post  How to get city weather from Yahoo Weather API using Javascript  and  How to get city name against google map latitude and longitude using javascript  then it would be probably more easy for you to get the required stuff. We'll get city name from Google Map GeoLocation and weather status from Yahoo Weather JavaScript API call. Below is sample example code for this combined. You can Google around to get more information about these API's. JavaScript Code: [code]var Wcity;// = "Gilgit"; var yahooWeatherAPI; var GoogleAPI; $(document).ready(function () { GetLocation(); }); function GetLocation() { navigator.geolocation.watchPosition(callback); } function callback(position) { GoogleAPI = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + position.coords.latitude + "," + position.coords.longitude + "&key=AIzaSyAswpJn5_eL3fmsnFocNmiSsgXVog3CsH8"; //Fetchin

How to get city name against google map latitude and longitude using javascript

Hi There, Before moving ahead please make sure you have a valid Google API key otherwise after few hits to google service it will throw a daily limit exceed exception in your ajax call. You need a Server API Key for this not Browser API Key from Google. You need to include below references in your HTML code first. [code] [/code] JavaScript Code: [code]function GetLocation() { navigator.geolocation.watchPosition(callback); } function callback(position) { GoogleAPI = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + position.coords.latitude + "," + position.coords.longitude + "&key=YOUR API KEY HERE"; //Fetching City Name $.getJSON(GoogleAPI, function (json) { if (Wcity == undefined) { Wcity = json.results[0].address_components[3].short_name; alert(Wcity); } }[/code] Please note that, in most of the cases Google map throws city name on " .address_components[ 3 ]" however you can change i

How to get city weather from Yahoo Weather API using Javascript

Hi There, Yahoo provides a superb JavaScript API to get weather updates for a specific city. More you can read Yahoo weather API documentation on Yahoo official website. However i am putting here a sample JavaScript code that how you can get city weather from Yahoo weather dynamically. JavaScript Code: [code]var Wcity = "Gilgit"; ///Fetching Weather Report yahooWeatherAPI = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22" + Wcity + "%2C%20PK%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys"; $.getJSON(yahooWeatherAPI, function (json) { var temp = Math.round((((json.query.results.channel.item.condition.temp - 32) * 5) / 9));// + "°"; $('#currentWeather').text(temp); $('#weatherCity').text(Wcity); }); [/cod

How to show "Loading..." in Jquery Ajax Call

Hi There, Well, that's pretty simple now. Below is the sample code that you can customize according to your needs. It will show a smooth Loading... with jquery effect. JQuery Code: $( "#loading" ).fadeIn( "slow" ); $.ajax({ crossDomain: true , contentType: "application/json; charset=utf-8" , url: "http://localhost:8080/Service.asmx/GetEmployessJSON" , data: { UserName: GetUserName(), Month: Month, Year: Year }, // example of parameter being passed dataType: "jsonp" , success: onDataReceived }); function onDataReceived(data) { $( "#loading" ).fadeOut(); $( "#myDiv" ).text(data.MyCustomProperty); } HTML Code: <div id= "loading" style= "display: none;" > Loading.... &

How to consume cross site asmx returned Json service with Javascript

Hi There, If you are trying to access a web service which is hosted on other domain or port or outside the network, you need to use jsonp instead of json. After spending hours, finally i found a solution on stackoverflow ( the only friend site of developers :o)  Thanks to NickG for writing this answer). You can read the inside story of this issue on the actual question on stackoverflow. I am posting here the direct code which worked for me. Hope you get some clue from here. Javascript / Jquery Code: $ . ajax ({ crossDomain : true , contentType : "application/json; charset=utf-8" , url : "http://localhost:8080/Service.asmx/MyCustomMethodName" , data : { User : 'Admin' , Mon : 8 }, // example of parameter being passed dataType : "jsonp" , success : onDataReceived }); function onDataReceived ( data ) { aler