Wednesday 17 September 2014

PartitionPropertiesCache.RefreshPartitionProperties: Encountered error: System.InvalidOperationException: Operation is not valid due to the current state of the object.

Keyword: User Profile Synchronization Service wont start


When configure user profile sync service, I get this error:

User Profile Application: SynchronizeMIIS encounters an exception: System.NullReferenceException: Object reference not set to an instance of an object.  
 at Microsoft.Office.Server.UserProfiles.UserProfileImportJob.<>c__DisplayClass2.<IsTimerJobRunning>b__1()  
 at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass5.<RunWithElevatedPrivileges>b__3()  
 at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)  
 at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param)  
 at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode)  
 at Microsoft.Office.Server.UserProfiles.UserProfileImportJob.IsTimerJobRunning(UserProfileApplicationJob timerJob)  
 at Microsoft.Office.Server.Administration.UserProfileApplication.SynchronizeMIIS()  
 at Microsoft.Office.Server.Administration.ILMProfileSynchronizationJob.Execute()


This is because the FIM certificate has not been validated yet. The farm account which the sync service is running under must have access to Internet. This validation only needs to be done once, after the certificate is validated, you can disconnect Internet.



Thursday 11 September 2014

Error: "Not able to connect to search service to retrieve valid settings"

I tried to change the query of the search results webpart and I've got this:

Fix is to use the SharePoint management Shell and define your account as an SSA Admin.


Here's the code to add yourself as SSA admin:
$principal = New-SPClaimsPrincipal "<domain>\<user>" -IdentityType WindowsSamAccountName

$spapp = Get-SPEnterpriseSearchServiceApplication

$security = Get-SPServiceApplicationSecurity $spapp –Admin

Grant-SPObjectSecurity $security $principal "Full Control"

Set-SPServiceApplicationSecurity $spapp $security –Admin

Wednesday 23 July 2014

Link multiple EditForms or DisplayForms to a sharepoint list

My listitems are opened via an infopath form. Client wants a second aspx form to open the listitems.
(the infopath form only shows a subset of the fields but the aspx form shows all fields).

When opening the aspx form, sharepoint redirects me to the infopath form. Somewhere, a redirect was taking place.
After a lot experimenting, I found that not only do you need hide the original List Form Web Part but you also need to set the ControlMode to Display. Here are the 2 lines of code that need to be modified in the original List Form Web Part:
Change:
<ControlMode xmlns=”http://schemas.microsoft.com/WebPart/v2/ListForm”&gt;Edit</ControlMode>
To:
<ControlMode xmlns=”http://schemas.microsoft.com/WebPart/v2/ListForm”&gt;Display</ControlMode>
Change:
<IsVisible>true</IsVisible>
To:
<IsVisible>false</IsVisible>

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());  
 }  
 });  

Tuesday 27 May 2014

SharePoint 2013: Get UserProfile Properties with REST API

Thanks to 

http://www.vrdmn.com/2013/07/sharepoint-2013-get-userprofile.html


1) Get all properties of current user:

http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties



2) Get single property of current user:

http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties/PictureUrl
OR
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties?$select=PictureUrl



3) Get Multiple Properties for the current user:

http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties?$select=PictureUrl,AccountName



4) Get all properties of Specific User:


For Office 365/SharePoint Online:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='i:0%23.f|membership|vardhaman@siteurl.onmicrosoft.com'

For SharePoint 2013 On-Premise:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='domain\username'



5) Get Specific UserProfile Property of Specific User:


For Office 365/SharePoint Online:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='LastName')?@v='i:0%23.f|membership|vardhaman@siteurl.onmicrosoft.com'


For SharePoint 2013 On-Premise:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='LastName')?@v='domain\username'



6) Get Multiple UserProfile Properties for Specific User:


http://siteurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertiesFor

Sunday 18 May 2014

My validators are not working

This was working 

<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ForeColor="Red" ErrorMessage="* This field cannot be blank." ControlToValidate="FunctionGroup">
</asp:RequiredFieldValidator>

...

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ForeColor="Red" ErrorMessage="* This field cannot be blank." ControlToValidate="FunctionGroup">
</asp:RequiredFieldValidator>


As soon as I changed it to 

<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ForeColor="Red" ErrorMessage="* This field cannot be blank." ControlToValidate="FunctionGroup">
</asp:RequiredFieldValidator>

...

<!--

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ForeColor="Red" ErrorMessage="* This field cannot be blank." ControlToValidate="FunctionGroup">
</asp:RequiredFieldValidator>

 -->

it stopped working. So if you don't want to use validator, instead of commentting out it, delete it.

Thursday 1 May 2014

SharePoint Search REST API not returning all subsites

This query is not working !!! I have 10 subsites, but it only returns 2 of them.
https://serverURL/_api/search/query?querytext='path:"*********"  contentclass:STS_Web'&rowlimit=20

Solution is to add &trimduplicates=false at the end of the query.
https://serverURL/_api/search/query?querytext='path:"*********"  contentclass:STS_Web'&rowlimit=20&trimduplicates=false




SharePoint Designer Cache Locations

  • %APPDATA%\Microsoft\Web Server Extensions\Cache
  • %USERPROFILE%\AppData\Local\Microsoft\WebsiteCache

Monday 7 April 2014

XmlDocument.CreateElement automatically adds xmlns="". How to get ride of it?

Problem:
 <?xml version="1.0" encoding="UTF-8"?>  
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"   
  xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"   
  xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">  
  <url xmlns="">   
 .......................  
  </url>  
 </urlset>  

Solution:
When creating the url element, instead of using
 doc.CreateElement("url");  
use
 doc.CreateElement("url","http://www.sitemaps.org/schemas/sitemap/0.9");