Thursday, September 1, 2016

SharePoint JSOM : Alternative approach to nested executeQueryAsync with loops

Let’s assume that we need to get all pages in a site. Following are the steps we have to perform

  • Get all libraries
  • Get items in each library

Traditionally we would write a code like the below, but it will not provide expected response. This is due to the asynchronous nature of operations

Code that does not work

var context = SP.ClientContext.get_current();
var hostContext = new SP.AppContextSite(context, decodeURIComponent(getQueryStringParameter("SPHostUrl")));

var web = hostContext.get_web();
var lists = web.get_lists();
context.load(lists);

context.executeQueryAsync(
function () {
    var listEnumerator = lists.getEnumerator();
    while (listEnumerator.moveNext()) {
        var oList = listEnumerator.get_current();
        if (oList.get_baseType() === 1) {

            var camlQuery = new SP.CamlQuery();
            var items = list.getItems(camlQuery);
            context.load(items);
            context.executeQueryAsync(
                function () {
                    var listEnumerator = lists.getEnumerator();

                }, function (sender, args) {
                    console.log('error!');
                });
        }
    }
}, function (sender, args) {
    console.log('error!');
});

As the solution, I broke the functionality in to two methods using Deferred objects. I’ve written a blogpost on Deferred objects and you can find it from here. Following is the preferred approach.

Working code with Deferred objects

function getSitePages()
{
    var context = SP.ClientContext.get_current();
    var hostContext = new SP.AppContextSite(context, decodeURIComponent(getQueryStringParameter("SPHostUrl")));

    var web = hostContext.get_web();
    var lists = web.get_lists();
    context.load(lists);

    context.executeQueryAsync(
    function () {
        var listEnumerator = lists.getEnumerator();
        while (listEnumerator.moveNext()) {
            var oList = listEnumerator.get_current();
            if (oList.get_baseType() === 1) {

                var promise = getListItems(oList).then(function (state) {
                    console.log(state);
                });

            }

        }
    }, function (sender, args) {
        console.log('error!');
    });
}

function getListItems(list) {
    var dfd = $.Deferred();

    var context = SP.ClientContext.get_current();
    var hostContext = new SP.AppContextSite(context, decodeURIComponent(getQueryStringParameter("SPHostUrl")));
           
    var camlQuery = new SP.CamlQuery();
    camlQuery.ViewFields = "<FieldRef Name='FileExtension' /><FieldRef Name='Title' />";
    camlQuery.set_viewXml("<View><Query><Where><Or><Contains><FieldRef Name='FileLeafRef' /><Value Type='Text'>.aspx</Value></Contains><Contains><FieldRef Name='FileLeafRef' /><Value Type='Text'>.html</Value></Contains></Or></Where></Query></View>");
    var items = list.getItems(camlQuery);
    context.load(items);

    context.executeQueryAsync(
        function () {
            var itemsCount = items.get_count();
            if (itemsCount > 0) {
                obj = {};
                obj.ListName = list.get_title();
                obj.ListPages = [];

                for (var i = 0; i < itemsCount; i++) {
                    var item = items.itemAt(i);
                    obj.ListPages.push(item.get_item('FileRef'));
                }

                dfd.resolve(obj);
            }
                   
        }, function (sender, args) {
            dfd.reject(sender, args, errorMsg);
        });

    return dfd.promise();
}

Thursday, August 25, 2016

Resolving SharePoint PowerPivot Service error–“We're no longer connected to the database and can't refresh your connection. please close and reopen the workbook and refresh it”

One of my SharePoint environment had all SharePoint related services configured in one server (Single server topology). PowerPivot service application was one of them. Due to various reasons the Server had very limited resources.

Due to resource limitation, I was getting the above issue repeatedly. Until I upgrade the server I performed following actions to resolve the issue.

1. Restart PowerPivot instance in my SQL Server

image

2. Navigate to Manage Service Applications > Excel Services Application > Data Model Settings, and check the PowerPivot instance is available

image

3. Navigate to “Service on this Server” and restart “Excel Calculation Services” service

image

4. Navigate to “Service on this Server” and restart “SQL Server PowerPivot System Service ” service

image

5. Check the firewall and the network connectivity between SharePoint server and PowerPivot SQL instance

Wednesday, August 17, 2016

Collab365 - SharePoint Framework the future of SharePoint development

The largest online conference for SharePoint, Office365 and Azure is just around the corner. I will be speaking on the topic of “SharePoint Framework the future of SharePoint development

600x200_speakerbadge_GC

You can register by navigation to this site

SharePoint Framework

SharePoint Framework, a page and part model that enables fully supported client-side development, easy integration with the Microsoft Graph and support for open source tooling. This will be the trend for any SharePoint customization. In this session I will describe the SharePoint framework and walkthrough a practicel sample which uses AngularJS and Kendo UI. Furthermore I will talk about the approach we take to migrate current SharePoint solutions to the SharePoint Framework

In this session I will try to talk about the following

  • SharePoint Framework in general
  • Advantages of SharePoint Framework
  • How to migrate current projects
  • SharePoint Framework with AngularJS
  • SharePoint Framework with Kendo UI
  • Client side / OpenSource tooling
  • New solution deployment and release mangement
  • Demonstrations

Sunday, July 17, 2016

Disaster Recovery for SharePoint farms in Microsoft Azure IaaS using Azure Recovery Services

I had to implement Disaster Recovery (DR) strategy to one of my SharePoint farms deployed in Microsoft Azure. I used Azure Recovery Services to achieve the goal in addition to SharePoint site collection backups.

Following are the steps I used to create a recovery vault in my Microsoft Azure environment to protect my Virtual Machines

1. Look for Recovery Services vaults in Azure portal

image

2. Create a new vault

image

3. Select if you need locally redundant or geo-redundant storage. I selected locally redundant storage as my budget was limited

image

4. In this section we are creating a new Backup policy for Virtual Machines

image

image

5. In backup policy, specify required retention

image

6. Add virtual machines to the backup policy

image

7. Click on backup jobs to see the current status

image

8. We can see the backup configuration task has completed

image

9. But that’s not all. We have to execute the initial backup. Click on Azure Virtual Machines node to navigate to check current status

image

image

10. We have to select one Virtual Machine at a time to execute the initial backup

image

image

11. Once we run the initial backup job for each and every Virtual Machine in our SharePoint farm, we can see a result similar to the following

image

12. Once it is backed up according to the schedule, we can check the latest restore point as shown below

image

image

That is the easiest way to implement disaster recovery for a SharePoint farm hosted in Microsoft Azure.

Sunday, July 10, 2016

SharePoint 2013 in Azure IaaS–Map public url to internal DNS

One of my SharePoint environments was recently deployed in Microsoft Azure IaaS. I have following servers in that environment

  • Active Directory
  • SQL Server
  • Analysis Services Server
  • SharePoint Server

I have deployed the farm accordingly and created host named site collection using public URL “portal.contoso.com”.

I used following command to create the host based site collection

New-SPSite 'https://portal.contoso.com' -HostHeaderWebApplication 'https://portal.contoso.com' -Name 'Portal' -Description 'Portal' -OwnerAlias 'SP\SP_Admin' -language 1033 -Template 'BLANKINTERNETCONTAINER#0'

Then I mapped the public IP of the SharePoint server with my external DNS. Thereafter my SharePoint site is accessible from outside as below

But the public URL was not accessible within my server farm (e.g SharePoint server, or Analysis Services Server), And I need to have a more concrete solution than host files.

Following are the steps I used

1. Log in to domain controller and navigate to DNS Manager. Right click on Forward Lookup Zones and create new

image

 

 

 

 

 

 

image

image

image

image

2. Create new A record to SharePoint server

image

image

3. Test the connectivity

First clear the DNS cache

  • ipconfig /flushdns

image

That’s all we have to do. In the same way I had to map public URLs of my analysis services as well.

Wednesday, June 29, 2016

Change the address space of a Azure virtual network containing a functional server farm

I have recently deployed a SharePoint farm in Microsoft Azure Infrastructure as a Service (IaaS). That server farm contains following servers.

  • Domain Controller with DNS
  • File Server
  • SQL Server
  • Analysis Services Server
  • SharePoint Server

Furthermore I’ve configured Point-to-Site VPN connectivity as well. Following is how the environment was structured.

image

Everything looks good until I received a request to move everything to a different network address space. It seems that there was an internal network range which conflicts with my 11.0.0.0/16 address space. The only option is to move to a new virtual address space.

Following was the desired configuration.

image

I had few challenges to overcome

  1. Move the environment to a new address space without corrupting my servers
  2. Consume the existing Domain Controller and DNS
  3. Continue to use my SharePoint server

Luckily I got recommendations from my good friend Janaka and received a great help from Denny Cherry to find a solution. This post is written to summarize the approach I took to move my environment to a new address space.

Okay. Let’s start the migration.

Following are the steps I followed.

1. Stop and deallocate all servers in the environment.

2. In Domain Controller remove the static IP assignment

image

3. Add a new Address Space in Virtual Network

image

4. Add new Subnets in that Address Space

image

5. I have to execute some PowerShell commands. I need to get the names of network cards in each server prior to that

image

6. First we need to connect to the environment

Login-AzureRMAccount
Get-AzureRmSubscription
Get-AzureRmSubscription –SubscriptionName "My Subscription" | Select-AzureRmSubscription –SubscriptionName "My Subscription"

7. Declare variables

$rgname = "TRS-Test-Res-01"
$vnetname = "TRS-Test-Net-01"
$subnetName1 = "TRS-Test-Sub-01"
$subnetName2 = "TRS-Test-Sub-02"

$adNICName = "trs-test-dc-01646"
$fsNICName = "trs-test-fs-01971"
$dbNICName = "trs-test-db-01899"
$asNICName = "trs-test-as-01350"
$spNICName = "trs-test-sp-01892"

8. Get Virtual Network and Subnets

$vnet = Get-AzureRmVirtualNetwork -ResourceGroupName $rgname -Name $vnetname
$subnet1 = Get-AzureRmVirtualNetworkSubnetConfig -VirtualNetwork $vnet -Name $subnetName1
$subnet2 = Get-AzureRmVirtualNetworkSubnetConfig -VirtualNetwork $vnet -Name $subnetName2

9. Migrate the first server (Domain Controller)

$nicAD = Get-AzureRmNetworkInterface -ResourceGroupName $rgname -Name $adNICName
$nicAD.IpConfigurations[0].Subnet = $subnet1
Set-AzureRmNetworkInterface -NetworkInterface $nicAD

I have to do some extra steps to update the DNS server (Activities from step 10 to step 13).

10.  Start the Domain Controller server

11. In Virtual Network set the custom DNS

image

But still it shows 11.0.0.4 as the DNS server, when I checked within the domain controller

image

12. Execute following commands and restart the domain controller

  • ipconfig /flushdns
  • ipconfig /registerdns
  • dcdiag /fix

image

image

image

13. Check ipconfig /all again after the restart

image

Now the DNS servers are updated properly

14. Now we have to migrate other servers

#File Server
$nicFS = Get-AzureRmNetworkInterface -ResourceGroupName $rgname -Name $fsNICName
$nicFS.IpConfigurations[0].Subnet = $subnet1
Set-AzureRmNetworkInterface -NetworkInterface $nicFS


#SSAS Server
$nicAS = Get-AzureRmNetworkInterface -ResourceGroupName $rgname -Name $asNICName
$nicAS.IpConfigurations[0].Subnet = $subnet1
Set-AzureRmNetworkInterface -NetworkInterface $nicAS


#DB Server
$nicDB = Get-AzureRmNetworkInterface -ResourceGroupName $rgname -Name $dbNICName
$nicDB.IpConfigurations[0].Subnet = $subnet2
Set-AzureRmNetworkInterface -NetworkInterface $nicDB


#SharePoint Server
$nicSP = Get-AzureRmNetworkInterface -ResourceGroupName $rgname -Name $spNICName
$nicSP.IpConfigurations[0].Subnet = $subnet2
Set-AzureRmNetworkInterface -NetworkInterface $nicSP

15. Once all servers are migrated we need to restart them

16. Now we can delete Subnets from my previous environment (TRS-Test-Sub-01 and TRS-Test-Sub-02)

image

image

17. Later we can delete the Address Space of my previous environment

image

That’s all I had to do. Hope this helps someone .

Thursday, June 16, 2016

How to remember my windows credentials for a SharePoint site

When we access a SharePoint site outside the domain, we get the annoying login prompt although we ask our browser to remember our credentials

image

How to get rid of that login prompt and automatically navigate to the site. Following were the steps I used

Settings in Internet Options

image

image

image

image

image

image

Settings in Credentials Manager

image

image

That’s all we have to do.