Saturday 5 July 2014

Get the Manager of the Current SharePoint user Using SPServices and GetUserProfileByName

Introduction
We  get the current user’s manager and put the value into a Person or Group column in a list. This one only works in SharePoint Server 2010 & SharePoint Foundation .because the UserProfileService Web Service is only available there. The code is relatively straightforward: a call to SPServices to get the results from  GetUserProfileByName and then a little more code to poke it into the appropriate Person or Group column. In this case, the Person or Group column is called ‘Manager’

Code  Steps
<script type="text/javascript" src="../../JSLibrary/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="../../JSLibrary/jquery.SPServices-0.4.8.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        var managerName;
        var userName = $().SPServices.SPGetCurrentUser();
        $().SPServices({
            operation: "GetUserProfileByName",
            async: false,
            AccountName: userName,
            completefunc: function (xData, Status) {
                managerName = $(xData.responseXML).text();
                var managerLength = managerName.length;
                var indexofManager = managerName.indexOf("Manager");
                managerName = managerName.substring(indexofManager + 13, managerLength);
                var indexOffalse = managerName.indexOf("false");
                managerName = managerName.substring(0, indexOffalse);
            }
        });
        var peoplepicker = $("tr:contains('Reporting Manager'):last").find("div[title='People Picker']");
        peoplepicker.html(managerName);
    });</script>
 
The available values from GetUserProfileByName in sharepoint 2010 environment are:
  • UserProfile_GUID
  • AccountName
  • FirstName
  • LastName
  • PreferredName
  • WorkPhone
  • Office
  • Department
  • Title
  • Manager
  • AboutMe
  • PersonalSpace
  • PictureURL
  • UserName
  • QuickLinks
  • WebSite
  • PublicSiteRedirect
  • SPS-Dotted-line
  • SPS-Peers
  • SPS-Responsibility
  • SPS-Skills
  • SPS-PastProjects
  • SPS-Interests
  • SPS-School
  • SPS-SipAddress
  • SPS-Birthday
  • SPS-MySiteUpgrade
  • SPS-DontSuggestList
  • SPS-ProxyAddresses
  • SPS-HireDate
  • SPS-LastColleagueAdded
  • SPS-OWAUrl
  • SPS-ResourceAccountName
  • SPS-MasterAccountName
  • Assistant
  • WorkEmail
  • CellPhone
  • Fax
  • HomePhone
Summary
In this blog we get Current user manager name and assign New/edit /display form using client side jquery and SPServices. 

Replace Add New Item Link Text to Something Different Link Text

Introduction 

This article explores the user’s requirement to change the "Add New Item" link text to " Different Link text", so that it becomes more meaningful on the list.



Solution

In the Content Editor Web Part, Place the JavaScript that manipulates the Add New Item text. In Detail:

1. Go to the target page >> Site actions>> Edit Page

2. Insert a CEWP just below the list view web part.

3. Place the cursor in CEWP, Click on "Edit HTML Source" link from the HTML Ribbon Item's drop down menu.


4. In the Content Editor web part enter the script:

<script type="text/javascript"> 
document.getElementById("idHomePageNewItem").innerHTML="Add New InterviewTracker"
</script



5. Save the page! watch the result in action.

Conditional Formatting with Calculated Columns in SharePoint 2010


Introduction
There are a variety of ways to add color, images coding to your SharePoint lists and document libraries, from embedding custom code on your page to creating data view web parts with conditional formatting in SharePoint.

Here suppose we have a list that contains a calculated field as Status column. If we write the formula for the calculated column like below:
Then the list will appear like below:



Suppose we have a list that contains a calculated column as progress Indicator and if we write the formula like below:

 Then the list will appear like below:
The technique used here is a combination of Calculated Columns and CSS/images styling on a list.

Create a SharePoint 2010 List Definition

In this article we will explain how to create a SharePoint 2010 List Definition using Visual Studio 2010.

Open Visual Studio 2010  then select "File" -> "New" -> "Project...".

Select the Visual C#  -> SharePoint 2010 --> List Definition project template.

Enter "MyTestList" in the Name TextBox and click on OK.

List Definition

In the SharePoint Configuration Wizard select "Deploy as farm solution" and click on "Next".

Next

Enter "MyTestList" in the What is the display name of the list definition? TextBox.

Select "Custom List" in the What is the type of the list definition? Drop-down box.

Custom List

In the Solution Explorer, expand ListInstance1 and open the Elements.XML file:

Solution Explorer

Within the ListInstance element change the Title attribute to MyTestList and change the TemplateType attribute to 10009.
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <Elements xmlns="http://schemas.microsoft.com/sharepoint/">  
  3.   <ListInstance Title="MyTestList"  
  4.                 OnQuickLaunch="TRUE"  
  5.                 TemplateType="10009"  
  6.                 Url="Lists/MyTestList-ListInstance1"  
  7.                 Description=" My Test List Instance">  
  8.   </ListInstance>  
  9. </Elements>  
Now, open the Elements.xml file that is on the same level as ListDefinition1.

Within the ListTemplate element, change the Type attribute to “10009” and add the DisallowContentTypes=”FALSE” attribute, as shown below:
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <Elements xmlns="http://schemas.microsoft.com/sharepoint/">  
  3.     <!-- Do not change the value of the Name attribute below. If it does not match the folder name of the List Definition project item, an error will occur when the project is run. -->  
  4.     <ListTemplate  
  5.         Name="ListDefinition1"  
  6.         Type="10009"  
  7.         BaseType="0"  
  8.         DisallowContentTypes="FALSE"  
  9.         OnQuickLaunch="TRUE"  
  10.         SecurityBits="11"  
  11.         Sequence="410"  
  12.         DisplayName="MyTestList"  
  13.         Description="My Test List Definition"  
  14.         Image="/_layouts/images/itgen.png"/>  
  15. </Elements>  
Insert the following XML into the top of the Elements element in the Elements.xml file. This XML describes the MyTestList Item content type the list will store.
  1. <ContentType  
  2.       ID="0x010089E3E6DB8C9B4B3FBB980447E313CE94"  
  3.       Name="My Test List"  
  4.       Group="Custom Content Types"  
  5.       Description="My Test List content type."  
  6.       Version="0">  
  7.       <FieldRefs>  
  8.         <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" />  
  9.         <FieldRef ID="{cb55bba1-81a9-47b6-8e6c-6a7da1d25602}" />  
  10.         <FieldRef ID="{0248c82f-9136-4b3a-b802-d0b77280b3bc}" />  
  11.         <FieldRef ID="{aa4a82dd-5b32-4507-9874-4e1c7bca3279}" />  
  12.       </FieldRefs>  
  13. </ContentType>  
Insert the following XML into the top of the Elements element in the Elements.xml file. This XML describes the Fields the MyTestList Item content type uses.
  1. <Field Type="Note" DisplayName="Title" Required="FALSE" NumLines="6" RichText="FALSE" Sortable="FALSE" ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" StaticName="Title" Name="Title" Group="Custom Columns" />  
  2.    
  3.   <Field Type="Note" DisplayName="ID" Required="FALSE" NumLines="6" RichText="FALSE" Sortable="FALSE" ID="{cb55bba1-81a9-47b6-8e6c-6a7da1d25602}" StaticName="ID" Name="ID" Group="Custom Columns" />  
  4.    
  5.   <Field Type="Text" DisplayName="Name" Required="FALSE" MaxLength="255" ID="{0248c82f-9136-4b3a-b802-d0b77280b3bc}"StaticName="Name" Name="Name" Group="Custom Columns" />  
  6.    
  7.   <Field Type="Text" DisplayName="Course" Required="FALSE" MaxLength="255" ID="{aa4a82dd-5b32-4507-9874-4e1c7bca3279}"StaticName="Course" Name="Course" Group="Custom Columns" />  
In the Solution Explorer, open Schema.xml.

Add the EnableContentTypes=”TRUE” attribute to the List element inside of the Schema.xml file.
  1. <List xmlns:ows="Microsoft SharePoint" EnableContentTypes="TRUE" Title="MyTestList"   
  2.                        FolderCreation="FALSE" Direction="$Resources:Direction;"   
  3.                                  Url="Lists/MyTestList-ListDefinition1" BaseType="0"   
  4.                                xmlns="http://schemas.microsoft.com/sharepoint/">  
Insert the following XML into the ContentTypes element in the schema.xml file. This XML describes the MyTestList Item content type this list will store.
  1. <ContentTypes>  
  2.       <ContentTypeRef ID="0x010089E3E6DB8C9B4B3FBB980447E313CE94" />  
  3.       <ContentTypeRef ID="0x01">  
  4.         <Folder TargetName="Item" />  
  5.       </ContentTypeRef>  
  6.       <ContentTypeRef ID="0x0120" />  
  7. </ContentTypes>  
Insert the following XML into the Fields element. This XML describes the fields the list will store. These are directly related to the fields in the Content Type we added in the previous step.
  1. <Fields>    
  2.       <Field Type="Note" DisplayName="Title" Required="FALSE" NumLines="6"   
  3. RichText="FALSE" Sortable="FALSE" ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" StaticName="Title" Name="Title"Group="Custom Columns" />  
  4.    
  5.       <Field Type="Note" DisplayName="ID" Required="FALSE" NumLines="6" RichText="FALSE" Sortable="FALSE" ID="{cb55bba1-81a9-47b6-8e6c-6a7da1d25602}" StaticName="ID" Name="ID" Group="Custom Columns" />  
  6.    
  7.       <Field Type="Text" DisplayName="Name" Required="FALSE" MaxLength="255" ID="{0248c82f-9136-4b3a-b802-d0b77280b3bc}"StaticName="Name" Name="Name" Group="Custom Columns" />  
  8.    
  9.       <Field Type="Text" DisplayName="City" Required="FALSE" MaxLength="255" ID="{aa4a82dd-5b32-4507-9874-4e1c7bca3279}"StaticName="City" Name="Course" Group="Custom Columns" />     
  10. </Fields>  
Insert the following XML into the ViewFields element in the 2nd view, BaseViewID="1":
  1. <ViewFields>  
  2.           <FieldRef Name="Attachments"></FieldRef>  
  3.           <FieldRef Name="LinkTitle"></FieldRef>  
  4.           <FieldRef Name="Title"></FieldRef>  
  5.           <FieldRef Name="ID"></FieldRef>  
  6.           <FieldRef Name="Name"></FieldRef>  
  7.           <FieldRef Name="City"></FieldRef>  
  8. </ViewFields>  
Right-click on the project and select Deploy:
Deploy

After deploying a List Definition, check this list in web application:

Go to Site Action -> More Options

Options

You can see that your MyTestList template is created in the Installed Items template:

Installed Items template

SharePoint 2013 - Uploading Multiple Attachments To The New Item On List Using JSOM And REST API

  Introduction In this article, we will explore how we can attach multiple attachments to the new item on list using JSOM and REST API. Ther...