Wednesday, April 23, 2014

Filter Predecessor by Projects in SharePoint 2010 Task List

We created a Task List for the internal portal to assign tasks within our team members. The Predecessor field in the Task list lists downs all the values entered for the Title field. It grows when we keep adding items to the list. To overcome this problem, we decided to add a field call Project and filter the Predecessor by projects. Following section describes how to achieve this.

To add values to the Project dropdown list, create a custom list named ‘Projects’ and use that list as a lookup field. Add some projects to the list. These project names will be displayed at the Task List at the dropdown list.

1. Next create a Task List named ‘Project Tasks’.

2. Create a Lookup column named ‘Project’, to list down available projects with the following information.

clip_image002

3. Next we are going to edit the form with InfoPath to do the customization. Click on the ‘Customize Form’ to open the form.

clip_image004

The form will be opened in InfoPath 2010.

clip_image006

4. Right click on Project field and select Drop-Down List Properties.

5. Select ‘Get choices from an external data source’ and click Add.

clip_image008

6. Create new data connection using the Data Connection Wizard.

7. Select Receive data option

clip_image010

8. Select the source as SharePoint library or list.

clip_image012

9. Select the ‘Projects’ list.

clip_image014

10. Select ID and Title fields.

clip_image016

11. Don’t select Store a copy of the data in the form template option.

clip_image018

12. Enter the data connection name as ‘Projects1’ and click Finish.

clip_image020

We have created the data connection for the Projects dropdown list.

13. Set the Value and the Display name properties as ID and Title respectively.

clip_image022

Next we need to do the same steps for the Predecessor field as well.

14. Right click on the Predecessor field and select Multiple-Selection List Box Properties and create a new Data Connection.

15. From ‘SharePoint library or list’ select ‘Project Tasks’, select ‘Title’, ‘ID’, and ‘Project’ column.

16. Don’t check the box for making a copy of the data in the form Template.

17. Do not check the box that asks for automatically retrieving data when the form is opened. Save the external data source as ‘Project Tasks1′

18. Set ID and Title for the Value and the Display name respectively.

We are almost done. Next we need to do the filtering for the Predecessor with the following steps.

19. Click on the xPath button at the properties dialog next to the ‘Entries’.

clip_image024

20. Click on the ‘Filter Data’ button and Click Add.

clip_image026

21. At the first column, pick ‘Select a field or group’.

clip_image028

22. A window pops up .Select the ‘Main’ data source, click on ‘dataFields’ and select ‘Project’

clip_image030

23. In the second column, choose ‘equals to’.

24. At the third column, choose ‘select a field or group’. Again a window pops up. Select the ‘Project Tasks1’ datasource, click on ‘dataFields’ and select ‘Project’. Click OK.

clip_image032

Your filter data will look like Project = Project. Next we are going to add some rules to the Project dropdown list.

25. Select the Project column and click on ‘Add Rule’. Select ‘The Field Changes’ and select ‘Query for Data’.

clip_image034

26. Now choose the Data connection ‘Project Tasks1′ and click OK.

clip_image036

27. Again add a new rule for the Project dropdown list. This time select ‘The Field Changes’ and select ‘Set a Field’s Value’.

28. Choose field ‘Predecessor’ and leave the value empty.

clip_image038

We are done now. Quick publish the Form. You will see the following when you try to add new item.

clip_image040

Tuesday, November 26, 2013

Enable or Disable Developer Dashboard in SharePoint 2013

To enable or disable Developer Dashboard in SharePoint 2013, use the following powershell script.

$contentService = ([Microsoft.SharePoint.Administration.SPWebService]::ContentService)
$devDashboardSettings =$contentService.DeveloperDashboardSettings
if($devDashboardSettings.DisplayLevel -eq "On){
$devDashboardSettings.DisplayLevel ="Off"
} else{
$devDashboardSettings.DisplayLevel ="On"
}
$devDashboardSettings.Update()


Monday, November 11, 2013

Replace SharePoint 2010 out-of-the-box Search box with custom control

When you create a SharePoint site using any templates, it will create a search box at the top right of the page and says ‘Search this site…’. There may be some situations you can’t go with out-of-the-box search box. This article will explain how to replace the OOTB search box with a custom control.

Create a SharePoint custom web part to replace the search box and include all your custom logics.

At the Elements.xml file of the web part include the following section.
xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/" >
<Control      Id="SmallSearchInputBox"
Sequence="23"         ControlClass="Search.WebParts.SearchAutoSuggestionTextBoxWebPart.SearchAutoSuggestionTextBoxWebPart"
              ControlAssembly="$SharePoint.Project.AssemblyFullName$">
</Control>
</Elements>

This will register your control through feature elements. You must specify the following properties;

Id: Give an Id for the custom control. The Id name of the search control is ‘SmallSearchInputBox’ (as specified in the master page).
Sequence: Define a lowest sequence number. If you define another control with same Id and with a lowest sequence number, the lowest value will be used.
ControlClass: Specify the code behind class file (fully qualified name) of the control.

You have created the search box. Next step is to replace the OOTB search box at the master page. You need to modify the master page to complete this.

Find the DelegateControl used for the search box.
<SharePoint:DelegateControl ID="DelegateControl1"
runat="server"
ControlId="SmallSearchInputBox" />
If you have specified a different name for the control, you need to give the correct Control Id instead.

Deploy the feature and check; the OOTB search box is replaced.

Thursday, October 3, 2013

Consume SharePoint web service using JavaScript in custom Web Parts

This article will explain how to consume web services using JavaScript in SharePoint Web Part.

Problem: you have developed a custom web service; you need to consume this in client side for a web part.

The following article will explain how to consume it in ASP.Net. http://msdn.microsoft.com/en-us/library/bb398998(v=vs.90).aspx It uses <asp:ScriptManager>  control to call the service reference. You can’t use this in SharePoint custom web parts because ScriptManager is already included in SharePoint. You will get a runtime error.

I use bellow steps to consume the service.
Open the ascx file of the Visual Web Part. Add <asp:ScriptManagerProxy>  control and set the service reference path and the script reference path as follows:
<asp:ScriptManagerProxy runat="server" ID="scriptManager">
<Services>
<asp:ServiceReference path="/_vti_bin/MyServices/SuggestionService.asmx" />
       </Services>
       <Scripts>
              <asp:ScriptReference Path="/_layouts/MyServices/Suggestions.js" />
       </Scripts>
</asp:ScriptManagerProxy>

I have deployed the custom web service at the following location: /_vti_bin/MyServices/SuggestionService.asmx
And I have added required JavaScript methods at the following location: /_layouts/MyServices/Suggestions.js

I’m calling the web service method at the onkeyup event of the input control.
<input type="text" id="fname" onkeyup="GetCompletionList()">
<div id="Results"></div>
                                 
GetCompletionList()  is the JavaScript method added at the Suggestions.js file.
The result will be display at the div.
Below is the Suggestions.js file:
var myProxy;

// Initializes global and proxy default variables.
function pageLoad() {
    // Instantiate the service proxy.
    myProxy = new Search.SuggestionService(); 
    // Set the default call back functions.
    myProxy.set_defaultSucceededCallback(SucceededCallback);
    myProxy.set_defaultFailedCallback(FailedCallback);
}

// Processes at the onKeyUp and calls the service GetCompletionList method. 
function GetCompletionList() {
    var completionList = myProxy.GetCompletionList();
}

// Callback function that
// processes the service return value.
function SucceededCallback(result) {
    var RsltElem = document.getElementById("Results");
    RsltElem.innerHTML = result;
}

// Callback function invoked when a call to
// the service methods fails.
function FailedCallback(error, userContext, methodName) {
    if (error !== null) {
        var RsltElem = document.getElementById("Results");

        RsltElem.innerHTML = "An error occurred: " +
            error.get_message();
    }
}


new Search.SuggestionService()  is the name of the class where WebMethod is defined.

namespace Search
{
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [WebService(Namespace = "http://tempuri.org/")]
    [System.Web.Script.Services.ScriptService]
    public class SuggestionService : WebService
    {
[WebMethod]
        public string GetCompletionList()
        {
            return "Results";
        }
    }
}


Now on onkeyup event of the input control, the result will be displayed in the div control at the end.

Friday, October 19, 2012

Check value exists in entity frame work.


Let’s say you want to check the existence of a particular value in the database table. For example I have a view named RoomTypeEntityView in edmx file as follows. I want to check a given RoomTypeName is exists or not. There are so many approaches to do this in entity framework.



One way to check the exsistence is get the result as ToList() and get the Count. This approach is little bit low performance. This need to check every row and to get the count.
Another easiest way is using Any() method. This will not check every row in the table. This will return true once it finds a match.

Example code:

public bool IsRoomTypeAlreadyExists(int accomodationId, string roomTypeName)
        {
            bool status = false;

            using (TripBagEntities entities = DataObjectFactory.CreateContext())
            {
               
                status = entities.RoomTypeEntityViews.Where(c => c.AccommodationId == accomodationId && c.RoomTypeName == roomTypeName).Any();

                return status;
            }
        }

Friday, August 24, 2012

Display multiline type column in SSRS


Recently I created a report using SharePoint list as the Datasource and the datasets are created by querying a SharePoint custom list. The report is displaying fine. But ‘multiple lines of text’ data types in the list are displaying like html text in the report.

Ex:
 <div class="ExternalClassD226A5A96C0C47E4A3D28396435DC63B"><p>Lost 47hrs due to engineering issue​</p></div>  

Providing a report as above to the end users is not meaning full. But SSRS provides the facility to format the text as human readable. The steps are very easy to follow .Follow the steps. 

1.       Right click on the particular cell and select Placeholder properties. 
2.       At the general tab select ‘HTML - Interpret HTML tags as styles’ option. 
3.       Click ok.

That’s it!.

Friday, July 27, 2012

Search Pdf files in SharePoint 2010


I created a document search application couple of days ago. This application contains large number of pdf files. When I type a search term it not results pdf files as search results. After some search on google I found that there are some installation and configuration should be done in SharePoint server. I thought to share this information.

To enable pdf search it is required to install PDF iFilter to the SharePoint server. You can download PDF iFilter at the following link. http://www.adobe.com/support/downloads/detail.jsp?ftpID=4025
Just double click and run the wizard to install PDF iFilter. Next you need to do some configurations in the registry. Follow the steps. 

1.       Click start, Run and type regedit to open the Registry Editor. 
2.       Go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\14.0\Search\Setup\Filters 
3.       Right click on the Filters and click New > Key 
4.       Type the key name as ‘.pdf’ 
5.       You need to add the following values to the key .pdf 


6.       To add values right click at the right side of the window and select New> string value. 
7.       Next go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\14.0\Search\Setup\ContentIndexCommon\Filters\Extension in the registry. 
8.       Right click on the Extension and click New > Key. 
9.       Add the key as .pdf 
10.   For the Default value add the following value. 


The configurations of the registry is complete. Next we have to add the file type in Central Administration. To add the file type follow the steps.
  
1.       Go to Manage service applications under Application Management 
2.       Select Search service application 
3.       At the left side click on File Types under Crawling section. 
4.       Click New File Type and add pdf as a file type.

The installation and configuration is complete to search pdf files in SharePoint. At the end you have to do IISReset on the SharePoint server and restart the SharePoint Server Search 14 and SharePoint Foundation Search V4 services.

Now you will be able to search pdf files in SharePoint 2010.
:)