Monday 16 June 2014

SharePoint 2013 Chrome Control Options

Looking through SP.UI.Controls.Debug.js, here are the options:

siteTitle

siteUrl

clientTag

appWebUrl

onCssLoaded

assetId

appStartPage

rightToLeft

appTitle

appIconUrl

appTitleIconUrl

appHelpPageUrl

appHelpPageOnClick

settingsLinks

language

bottomHeaderVisible

topHeaderVisible

Friday 13 June 2014

Get List Field Internal Name

You can get the internal name for a column by browsing to the List Settings > Edit Column and look at the QueryString. This will be url encoded but is a simple way of retrieving the internal name without writing any code. You will get something like: /_layouts/FldEdit.aspx?List=%7B37920121%2D19B2%2D4C77%2D92FF%2D8B3E07853114%7D&Field=Product%5Fx0020%5FDescription %5F is a '_'. The field name is Product_x0020_Description. The code option is to use: string itemInternalName = item.Fields["Field Display Name"].InternalName;

Thursday 12 June 2014

Different ways to get user name using javascript

Get user email

_spPageContextInfo.userLoginName

Using REST Service

 $(document).ready(function () {  
 var userid = _spPageContextInfo.userId;  
 function GetCurrentUser() {  
 var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";  
 var requestHeaders = { "accept" : "application/json;odata=verbose" };  
 $.ajax({  
  url : requestUri,  
  contentType : "application/json;odata=verbose",  
  headers : requestHeaders,  
  success : onSuccess,  
  error : onError  
 });  
 }  
 function onSuccess(data, request){  
  //var loginName = data.d.LoginName.split('|')[1];  
  var loginName = data.d.Title; 
  alert(loginName);  
 }  
 function onError(error) {  
  alert(error);  
 }  
 GetCurrentUser();  
 });  

Using JSOM

 $(document).ready(function () {   
 var currentUser;  
 // Ensure that the SP.js is loaded  
 if (SP.ClientContext != null) {  
  SP.SOD.executeOrDelayUntilScriptLoaded(getCurrentUser, 'SP.js');  
 }  
 else {  
  SP.SOD.executeFunc('sp.js', null, getCurrentUser);  
 }  
 function getCurrentUser() {  
  var context = new SP.ClientContext.get_current();  
  var web = context.get_web();  
  currentUser = web.get_currentUser();  
  context.load(currentUser);  
  context.executeQueryAsync(onSuccessMethod, onRequestFail);  
 }  
 function onSuccessMethod(sender, args) {  
  var account = currentUser.get_loginName();  
  var currentUserAccount = account.substring(account.indexOf("|") + 1);  
  alert(currentUserAccount);  
 }  
 // This function runs if the executeQueryAsync call fails.  
 function onRequestFail(sender, args) {  
  alert('request failed' + args.get_message() + '\n' + args.get_stackTrace());  
 }  
 });