Monday, 23 February 2015

Exception “The user does not exist or is not unique…”

Hi All,

Today new issue and solution J

Issue: We were adding the item into list using Java Script Object Model (JSOM). We have one field in list is of type UserMulti as

<Field ID="{}"
         Name="Users"
         DisplayName="Users"
         Type="UserMulti"
         UserSelectionMode="PeopleOnly"
         Required="TRUE"
         Group="My Site Columns">
  </Field>

We need to submit the multiple users to the list.

Following is the code snippet (sample code snippet J) we have to add the item in the list 

When we are adding single or two users in above user field it was working very fine.

But when we are trying to add three users then we are getting an exception: “The user does not exist or is not unique…” with following stack trace.

Fig 1. Exception while adding item in a list with MultiUser field from JSOM
Solution:

This seems to be strange issue since adding two users are working but not more than two users.

After digging more, it found that there is one property “Mult” which need to be specify. 

According to MSDN
Mult
Optional BooleanTRUE to allow a lookup field to contain multiple values. The default is FALSE.
So after setting this property fields schema looks as

<Field ID="{}"
         Name="Users"
         DisplayName="Users"
         Type="UserMulti"
         UserSelectionMode="PeopleOnly"
         Required="TRUE"
         Group="My Site Columns"
  Mult="TRUE">
  </Field>

After changing the field schema it started working like a charmJ


Thanks!


Feel free in case of any comments / feedback / suggestions

Wednesday, 4 February 2015

Exception "The server was unable to save the form at this time. Please try again." or "Site Feed web part - We’ve hit a snag"


Hi again,

Today couple of small issues and solutions J Issues: I upgraded my SharePoint 2013 farm solution in my development environment and was doing some unit testing. There were two exceptions I got having completely different features:




  1. I tried to add the item in announcement list and got the error “The server was unable to save the form at this time. Please try again.”  as
  2. At the same time when I tried to post in Site Feed web part, got the error “We’ve hit a snag. Looks like newsfeed was removed from the site, the site was deleted, or there’s some temporary network problem. You can try again later or stop following the site from the site pages.”  as
Solutions:
 

Thanks!

Enjoy reading :)

Feel free to comment / feedback if any or if you have any query :)




Monday, 2 February 2015

New properties in _spPageContextInfo variable in SharePoint Online / Office 365

Hi All,
 
Today, sharing one important finding. In our SP2013 farm solution project we were very heavily using Java Script variable _spPageContextInfo which SharePoint providing us.
 
There are various good blog post for this, one of those is  http://sympmarc.com/2013/03/26/using-_sppagecontextinfo-to-determine-the-current-sharepoint-context-in-script/. So I will not go into more details of it.
 
But recently I got a chance to use this variable with my SharePoint online site. Then I noticed there are few more properties which are available in SharePoint Online.
 
One of the important property userLoginName: In on premise version this property of _ spPageContextInfo is not available but available in SharePoint online. This seems to be very useful property since without extra call (and callback :) ) we directly get the user LogInName.
 
Couple of the other important properties are like isAppWeb, env etc. but I’ll explore those and may be write new post.

Thanks!

Enjoy reading J

Feel free to comment / feedback if any or if you have any query J

Sunday, 1 February 2015

Hiding getting started web part from each team site


Hi All,

Today new scenario, solution J

Scenario:



 In our project, we are using OOB team site for our team workspaces. So customer will be creating team workspaces using OOB team site. One of the requirement is, there should be no “GettingStartedWebPart” (as shown in following figure) on the home page.

Easiest way to remove the above web part is just click on “REMOVE THIS” link as shown in above figure.
But we need to automate this process. So customer no need to explicitly click the link every time new workspace is getting created.  So we can have a control / user control in which we will right the code to hide the web part. 
But again challenge is this should happen only once when first time page is getting loaded. Code should not be executed every time when workspace is accessed.
Background:
There is a hidden Site feature called “Basic WebParts”, which populates this “GettingStartedWebPart” in web part gallery. Also we don’t want to remove this web part from web part gallery.
Related to this there is one more concept, there is a web level feature “Getting Started” as


This feature is responsible for provisioning “GettingStarted.aspx” page and adding link to site action menu



Solution:
We have written one user control “RemoveGettingStartedWPFromPage.ascx”. From code behind we have hide the “GettingStartedWebPart” web part as (just sample code :))
        
           web.AllowUnsafeUpdates = true;
            string welcomePageUrl = web.RootFolder.WelcomePage;
           SPFile welcomePage = web.GetFile(welcomePageUrl);
if (welcomePage.CheckOutType == SPFile.SPCheckOutType.None || (welcomePage.CheckOutType != SPFile.SPCheckOutType.None && welcomePage.CheckedOutByUser.LoginName.Equals(web.CurrentUser.LoginName)))
{
     
              if (welcomePage.CheckOutType == SPFile.SPCheckOutType.None){
                   welcomePage.CheckOut();
              }
            using (SPLimitedWebPartManager webPartMngr =  
              welcomePage.GetLimitedWebPartManager(PersonalizationScope.Shared))
         {
          foreach (System.Web.UI.WebControls.WebParts.WebPart wp in webPartMngr.WebParts)
           {
              var webBrowsableObject = wp.WebBrowsableObject.ToString();   
             if (webBrowsableObject ==
                     "Microsoft.SharePoint.WebPartPages.GettingStartedWebPart") {
                  wp.AllowEdit = true;
                    wp.Hidden = true;
                    webPartMngr.SaveChanges(wp);
                 }
             }
          }
           welcomePage.CheckIn("Getting Started WebPart is Hidden!!");
}
 Added one feature and using feature added our user control to “AdditionalPageHead” control as
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Control Id="AdditionalPageHead" ControlSrc="~/_controltemplates/15/  
                                                /RemoveGettingStartedWPFromPage.ascx" />
</Elements>

Now this code will be executed when page will be loaded. But we want to execute this code only once and not every time workspace is get executed.
So we are deactivating the feature from the user control after hiding the web part as
// trying to deactivate the feature that this control is linked to so that this code will not run again.
                bool hasFeature = false;
                foreach (SPFeature f in web.Features)
                {
                    if (f.DefinitionId.ToString().Equals(customizationFeatureGuid, StringComparison.InvariantCultureIgnoreCase))
                    {
                        hasFeature = true;
                        break;
                    }
                }
                if (hasFeature)
                {
                    web.Features.Remove(new Guid(customizationFeatureGuid));
                 }
And we are done. This is the way to execute the code only once :)
But this solution is purely for farm solution, I’ll write new post soon for SharePoint online.
Also important point here is an idea to execute the particular code only once on the page.
Thanks!
Enjoy reading :)
Feel free to comment / feedback if any or if you have any query :)