Ads

Wednesday, 15 February 2017

Enable developer dashboard using powershell in SharePoint 2013


$content = ([Microsoft.SharePoint.Administration.SPWebService]::ContentService)
$dashboardSettings =$content.DeveloperDashboardSettings
$dashboardSettings.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::On
$dashboardSettings.Update()

Tuesday, 14 February 2017

Start list workflow from powrshell

$siteURL="Site URL"
$listName="List Name"
$site=Get-Spsite $siteURL
$web=$site.RootWeb
$list=$web.Lists[$listName]
$item=$list.Items[0]
$manager=$site.WorkFlowManager
$association=$list.WorkFlowAssociations[0]
$data=$association.AssociationData
$wf=$manager.StartWorkFlow($item,$association,$data,$true)

Get "CreatedBy" and "ModifiedBy" from list using client coding

<script language="ecmascript" type="text/ecmascript">

        var listItem;
        var list;
        var clientContext;

        function getFieldUserValue() {

            this.clientContext = SP.ClientContext.get_current();
            if (this.clientContext != undefined && clientContext != null) {
                var webSite = clientContext.get_web();
                this.list = webSite.get_lists().getByTitle("CustomList");
                this.listItem = list.getItemById(1);
                clientContext.load(this.listItem);
                this.clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed));
            }
        }

        function OnLoadSuccess(sender, args) {
            var fieldUserValueCreatedBy = this.listItem.get_item("Author");
            var fieldUserValueModifiedBy = this.listItem.get_item("Editor");
            alert("Created By: " + fieldUserValueModifiedBy.get_lookupValue() + "\n Modified By: " + fieldUserValueModifiedBy.get_lookupValue() + "\n");
        }


        function OnLoadFailed(sender, args) {
            alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
        }</script>

    <input id="btnGetFieldUserValue" onclick="getFieldUserValue()" type="button" value="Get Created by and Modified by" />

Connect SharePoint online using CSOM from console application


Create new console application project in VS 2013
R-click on References in the Solution Explorer --> click on Manage NuGet Packages.
Search for Microsoft.SharePointOnline.CSOM and then click on Install

Code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Security;
    using System.Text;
    using System.Threading.Tasks;
    using Microsoft.SharePoint.Client;
    namespace CSOMOffice365  
    {
        class Program  
        {
            static void Main(string[] args)  
          {
                string userName = "BlaBla.onmicrosoft.com";
                Console.WriteLine("Enter password.");
                SecureString password = GetPassword();  
                using(var clientContext = new ClientContext("SharePoint site URL"))  
                {
                    // SharePoint Online Credentials
                    clientContext.Credentials = new SharePointOnlineCredentials(userName, password);  
                    Web web = clientContext.Web;
                    clientContext.Load(web);
                    clientContext.ExecuteQuery();
                    Console.WriteLine("Title: " + web.Title + "; URL: " + web.Url);
                    Console.ReadLine();
                }
            }
            private static SecureString GetPassword()
          {
                ConsoleKeyInfo info;
                SecureString securePassword = new SecureString();
                do  
                {
                    info = Console.ReadKey(true);
                    if (info.Key != ConsoleKey.Enter)  
                    {
                        securePassword.AppendChar(info.KeyChar);
                    }
                }
                while (info.Key != ConsoleKey.Enter);
                return securePassword;
            }
        }
    }


List search using Angular JS

Before proceed, I recommend you to go through Learn Angular js for better understanding.

Lets assume to do search in a custom list called "ListA"

Create one js file "ListSearch.js" and upload in any library
var spApp = angular.module("spApp", []).controller("viewItemController", function($scope, $http) {
    var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('ListA')/items";
    $http({
        method: "GET",
        url: url,
        headers: {
            "accept": "application/json;odata=verbose"
        }
    }).success(function(data, status, headers, config) {
        var dataResults = data.d.results;
        $scope.contacts = dataResults;
    }).error(function(data, status, headers, config) {});
})

Create one html file with below html or we can put it in a content editor to get the result.

    <html>
   
    <head>
        <script type="text/javascript" src="/SiteAssets/jquery-3.0.0.min.js"></script>
        <script type="text/javascript" src="/SiteAssets/angular.min.js"></script>
        <script type="text/javascript" src="/SiteAssets/listSearch.js"></script>
    </head>
   
    <body>
        <h3>View Contacts</h3>
        <hr/>
        <div ng-app="spApp">
            <div ng-controller="viewItemController"> Search Items:<input type="text" placeholder="searchItems" ng-model="searchText" />
                <table>
                    <tr>
                        <th>Product</th>
                        <th>Total Sales</th>
                        <th>Sales Target</th>
                    </tr>
                    <tr ng-repeat="contact in contacts|filter:searchText">
                        <td>{{contact.Product}}</td>
                        <td>{{contact.Total_x0020_Sales}}</td>
                        <td>{{contact.Sales_x0020_Target}}</td>
                    </tr> <br /> </table>
            </div>
            <hr /> </body>
   
    </html>



Get lookup column values using REST


I have source list named: Managers
I have one site column Managers which is a lookup column to Managers--> Title column
I have another list "Details" where we use lookup column "Manager"

getListItems(_spPageContextInfo.webAbsoluteUrl,'?$select=Managers/Title,Managers/Id&$expand=Managers','Details',
function(items){
if(items.length > 0)
console.log(items[0].Managers.Title);
console.log(items[0].Managers.Id);
},
function(error){
console.log(error.responseText);
});

Language pack installation (Multilingual User Interface - MUI)

SP 2013 allows multiple languages. Lets enable Arabic language in SharePoint.

Download and install Arabic language from Microsoft site. Download link
Double click & install setup file

After install--> Run SharePoint product configuration wizard to upgrade farm

Now we can check the installation from CA --> Upgrade & Migration --> Check product & patch installation status --> Here we can see the installed language pack

Now open any SP site --> Site Settings --> language settings --> select Arabic language --> ok

Open Browser --> Settings -->Advance Settings --> language settings --> select Arabic --> Add
Also move Arabic as a default language

Now refresh the site and it will display content in Arabic language.
It will not change the custom web part titles.

Reference: One

Ads