Tuesday, 3 June 2014

Sorting the Lookup field values based on any columns on Lookup list using SPServices SPFilterDropdown

Hi Everyone,
 Today we will be seeing a common requirement which will used very frequently, and there is OOTB way to do this.

The requirement is "sorting the Lookup field values". Usually it gets sorted automatically "alphabetically".

Sometimes, we need to have them as in same order as they have stored in the list. For this we are going to sort the values of the lookup based on the ID on the lookup list.
Note : The lookup values can be sorted based on any columns. That depends on the requirement. For understanding i have used ID for that.

For this we are using SPServices, For using SPServices and to have a basic knowledge about SPservices, please refer here.

 $().SPServices.SPFilterDropdown({ //This is the function that does the sorting.
        relationshipList: "LookUp list", //This is the lookup list.
        relationshipListColumn: "Title", //This is the original column name from the lookup list as SharePoint knows it.
        relationshipListSortColumn: "ID", //This is the column in the lookup list to sort by.
        columnName: "LookUpcommitees", //This is the lookup field name .
        debug: true// have to be true on development times
    });


Have a good day:)

Saturday, 19 April 2014

Site Pages and Site Assets missing in your Newly Created SharePoint Site?

Sometimes when you create a site in SharePoint 2010, the Site Pages and Site Assets libraries are not created, yet other times, they are?

The answer lies in a feature called Wiki Page Home Page, which is enabled by default for Team Sites in SharePoint. However, other types of site templates may not activate that feature by default, and if that’s the case, those libraries won’t be there.

If you need them, you have a few options:
  • Activate the “Wiki Page Home Page” feature. The feature will create those libraries and will also create a wiki page and set it as the home (welcome) page for your site.
  • If you only need the libraries and don’t want your home page changed, you can have SharePoint Designer 2010 create the libraries for you:
    • Open SharePoint Designer.
    •  In the “Site Objects” pane on the left, click “Site Pages.” SP Designer will load the contents of the Site Pages library and tell you it’s empty. However, it also creates the Site Pages library for you in the process.
    • Do the same thing for “Site Assets” (also in the Site Objects pane). 
  • If you have code that depends on the existence of these libraries (such as a feature receiver), you can use two methods on the SPListCollection class to ensure the libraries are there:
    • EnsureSitePagesLibrary()
    • EnsureSiteAssetsLibrary()

Happy SharePointing!!!:)

Tuesday, 18 February 2014

Synchronous Event LookUp Value on After Properties - SharePoint

HI All,
 Today We will see about getting the value of a LookUp field in a Synchronous Event.
There is a major difference in getting the value of the same when the following two things are called.
1)properties.ListItem
2)properties.AfterProperties

For the first , properties.ListItem
We have to make call like this,
          
    SPFieldLookupValue prevItemValue = new SPFieldLookupValue(properties.ListItem["FieldName"] as string ?? string.Empty);
    string FieldNameListItem = prevItemValue.LookupValue;

And for the second, properties.AfterProperties

   SPFieldLookupValue newItemValue = new SPFieldLookupValue(properties.AfterProperties["FieldName"] as string ?? string.Empty);
   int str1 = newItemValue.LookupId;
   SPList targetList = properties.Web.Lists["Target List"];
   SPListItem targetItem = targetList.GetItemById(str1);
   string FieldNameAfterProperties = targetItem["ParentField"].ToString();


On seeing the piece of code for properties.ListItem we can easily understand the logic how it works.

For the second one, a small detour has been done to get the value.
On calling properties.AfterProperties we only get the Id of the particaular item and the value is missed. So for getting the value of that field in After properties we have to query the master list,s master column.

Hope you all understand. Please drop your queries for any further clarification.
Thanks for your Time.. See you on my next post...

Sunday, 16 February 2014

Bring back the BreadCrumb in SharePoint 2013

HI All,
 Today we will see how to add the breadcrumb in SharePOint 2013. To know about BreadCrumb, Please check here.

It seems like this feature has been removed in SharePoint 2013. But the real fact is that this BreadCrumb trail has been hidden from the End Users.

OK lets see how to get back the same.

1.Open your site with SharePoint designer

2.Navigate to All Files -> _catalogs -> master page

3.Edit the Seattle.master in advanced mode and copy all the code

4.By default it’s not possible to edit the original master. To create a new one click on File -> Blank Mater Page

5.Check out the new master, edit it in advanced mode, delete all the existent code and paste the one from the original Seattle

6.Search for <div class="ms-breadcrumb-dropdownBox" style="display:none;">
 Remove the CSS attribute, style="display:none;

7.Two lines bellow change the visible attribute of the SharePoint:PopoutMenu to true.

So Finally the code should look like,
<div class="ms-breadcrumb-dropdownBox">
<SharePoint:AjaxDelta id="DeltaBreadcrumbDropdown" runat="server">
 <SharePoint:PopoutMenu
  Visible="true"
  runat="server"
  ID="GlobalBreadCrumbNavPopout"


Thanks for your time. See you back on my next post.



Friday, 10 January 2014

Programmatically Hiding the "Overwrite existing files" checkbox for a single library,, Solution-2

Hi Sharepointers,

In one of my previous posts, I shared one of the two solutions for hiding checkbox in Upload.aspx page for a single document library.
This time I will share the second solution for the same issue.


Solution 2) Edit the Upload.aspx (application) page.

When u try to edit this page, it reflects on all the document libraries.
So we need to check to perform the action on a single library, and this check will be the List GUID from the URL.


<%

    if (Request.QueryString["List"] == "{651489A5-0C0D-4774-B6FF-B995BB06D82A}")

       {

                                OverwriteSingle.Visible=false;
                                UploadMultipleLink.Visible=false;
      }

%>


Substitute the above with your List ID.
For easily finding the GUID of a library u can refer my post here
That's it. Work is done :)

See u next time :)......

Monday, 30 December 2013

DataSheet View And People Picker issue

Hi All,
 Today i will share a weird issue i had gone through. Surely U will have to face it in some point of time.

Certainly everyone would have used Datasheet View. Have U ever checked People picker column in DataSheet View?

Bcoz when i tried, i got "Column Mismatch" error. When i tried the same entry in a Standard view, it got saved... So what is the prob and how to fix???

Finally, I fixed that after checking it for a Whole Day.
The Fix is ,
 U have to give atleast Read rights for the User to be entered in the People Picker.

People picker can validate user by name,email, id etc. in Standard View. But when you open it in Datasheet view then it does not validate the person by name,email. And instead of validating you will see small picker at person or group something like a choice column. You have to select from that.


Small one. But this will be certainly useful for you sometime..
Happy SharePointing...

Tuesday, 24 December 2013

Programmatically Hiding the "Overwrite existing files" checkbox for a single library

Hi All,
Last week i got a challenge for hiding the "Overwrite existing files" checkbox for a particular library.
First i thought it would be very easy , because my option was like adding a simple javascript to hide for that library.
I opened SharePoint Designer and tried adding javascript to that. It was not reflecting.. :(:(

On digging deep, I came to know that Upload.aspx is an application page and it is coming from the Layouts folder.
Ok finally i thought i found out the solution and tried changing the Upload.aspx page in the layouts folder. But the checkbox got hidden on all the pages..

Again i have to give a check on that so that it gets reflected for only one library. Finally i pointed out the List GUID in the URL of the page.

Then i tried and found 2 solutions for hiding checkbox for a single library.

Solution 1) Use this script in your master page

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready( function () {
        if (location.href.indexOf('0ABCE757-34A6-409D-A230-72382C924651') >= 0)
 // you must need to change GUID of your lib above
       {
            $("label:contains('Add as a new version to existing files')").prev('input').hide();
            $("label:contains('Add as a new version to existing files')").hide();
            $("a:contains('Upload Multiple Files...')").hide();
        }
    });
</script>

For easily finding the GUID of a library u can refer my post here


The second solution I will share on my next post. C ya!!!!