With “Apps” being the buzz word in SharePoint 2013, and if you could have started developing apps, you could have noticed that your App.js file starts with a statement as below:

“use strict”;

App.js enables you to access SharePoint objects using ECMAScript & the version being used is ECMAScript 5. ECMAScript 5’s strict mode is a way to opt in to a restricted variant of JavaScript. Strict mode is a way to introduce better error-checking into your code.

Strict mode makes several changes to normal JavaScript semantics.

  1. Strict mode eliminates some JavaScript silent errors by changing them to throw errors.
  2. Strict mode fixes mistakes that make it difficult for JavaScript engines to perform optimizations: strict mode code can sometimes be made to run faster than identical code that’s not strict mode.
  3. Strict mode prohibits some syntax likely to be defined in future versions of ECMAScript.

 

Below are the most important restrictions when you use strict mode,

  1. Using a variable without declaring it
  2. Writing to a read-only property
  3. Adding a property to an object whose extensible attribute is set to false
  4. Deleting a variable, a function, or an argument
  5. Deleting a property whose configurable attribute is set to false
  6. Defining a property more than once in an object literal
  7. Using a parameter name more than once in a function
  8. Using a future reserved keyword as a variable or function name
  9. Assigning an octal value to a numeric literal, or attempting to use an escape on an octal value
  10. The value of this is not converted to the global object when it is null or undefined
  11. The string “eval” cannot be used as an identifier (variable or function name, parameter name, and so on)
  12. You cannot declare a function inside a statement or a block
  13. If a variable is declared inside an eval function, it cannot be used outside that function
  14. The string “arguments” cannot be used as an identifier (variable or function name, parameter name, and so on)
  15. You cannot change the values of members of the local arguments object
  16. “with” statements not allowed

Note : Browsers not supporting strict mode will run strict mode code with different behavior from browsers that do, so don’t rely on strict mode without feature-testing for support for the relevant aspects of strict mode. Strict mode code and non-strict mode code can coexist, so scripts can opt into strict mode incrementally.


SharePoint 2007 (MOSS) & SharePoint 2010 have an option of “Sign in as different user” in the menu at the right top corner of the page. Developers used this handy menu to test their customizations for different users by logging in with another account. But in SharePoint 2013, you will not be finding that  option. You just can sign-out from the site, re-open the browser & login again.

Not sure is it removed with a reason. But MS references say it is a problem with SharePoint 2013.

So, How do I login as different user to my SharePoint site? There are two ways you can do it:

1) IE’s “Run as different user” option

This is the way old method we used to start any application with a different credentials. That is by using the Run as different user option that will be visible if you hold the Shift key when you right-click a program icon.

Start Internet Explorer by using the Run as different user option, where you can provide the different credentials and then go to the SharePoint site.

2) Navigating to the close connection page

More simple way is to browse the close connection page. Hit the below URL in your browser where you have opened your site.

http://siteurl/_layouts/closeConnection.aspx?loginasanotheruser=true

You will be getting a pop up to enter the new credentials where you can sign in as different user.

Note : This option uses an unsupported browser feature which is unreliable and may causes other issues. Currently this option does not work in IE 10 and Safari.

 

Hope it helps.

 

2013 in review

Posted: January 6, 2014 in Uncategorized

The WordPress.com stats helper monkeys prepared a 2013 annual report for this blog.

Here’s an excerpt:

The Louvre Museum has 8.5 million visitors per year. This blog was viewed about 80,000 times in 2013. If it were an exhibit at the Louvre Museum, it would take about 3 days for that many people to see it.

Click here to see the complete report.


With the experience of working on webparts in SharePoint 2007 & 2010, I started creating a new SharePoint hosted app as soon as I set up my 2013 developer machine & VS 2012. With a little bit knowledge on the solution structure that every script we write should go in to the  App.js file, I quickly opened it. Visual Studio, pre-loads the file with a piece of code to display a welcome message with the current logged in user. In an urge to see my app working on the site, I deployed the app.

BANGGG!!  Visual studio threw its first error “Apps are disabled on this site“. Digging more in to it, found lot more goes at the configuration before an app can be deployed. Below are the various issues/errors I have faced and the solutions I have found to resolve them to get my app deployed & work successfully.

<<<GOLDEN RULE : Make sure you deploy your app only with an account which is not part of the farm administrators group>>>

“Apps are disabled on this site”

To resolve this issue, you need to configure App URLs in the central Administration. Open Central Administration -> Apps ->Configure App URLs

By opening this page you may end up with the below error.

“The Subscription Settings service and corresponding application and proxy needs to be running in order to make changes to these settings”

Reason being that app requires below two service application to be created & running.

  1. App Management Service
  2. Microsoft SharePoint Foundation Subscription Settings Service

Going to the System Setting -> Manage services on server, I saw both of these services Started & running without any issues.

SPHostedAppServiceApps

Further debugging, when I checked the service applications list, I could see only the App Management Service application & not the Microsoft SharePoint Foundation Subscription Settings Service application.

Though App Management Service is created as part of the set-up, you need to create the later one manually. And the trick here is that you need to create it through PowerShell. Below is the commands..

>> $managedAccount = Get-SPManagedAccount “domain\accountname”
>> $appPool = New-SPServiceApplicationPool -Name SubscriptionServiceAppPool -Account $managedAccount
>> $serviceApp = New-SPSubscriptionSettingsServiceApplication -ApplicationPool $appPool -name “Subscription Settings Service Application” -DatabaseName “SubscriptionSettingsDB”
>> $serviceAppProxy = New-SPSubscriptionSettingsServiceApplicationProxy -ServiceApplication $serviceApp

Make sure you are using a managed account in the above snippet to avoid the object reference error. You can register your account as a SharePoint Managed account at Security -> Configure Managed Accounts in Central Administration (Being a dev environment we attempt to use our own domain account for installation/run services applications & app pools/farm administration. But remember the golden rule, don’t deploy app using the farm admin account. I would suggest, use your account only for developing & deploying but another service account to run the service applications & app pools). 

Now going back to where we started, Configure App URLs page, I got the below error.

“Settings or services required to complete this request are not currently available.  Try this operation again later.  If the problem persists, contact your administrator”

An IIS reset solved this issue. Once the page loads successfully, provide your app domain and the prefix details.

SPHostedAppCnfgAppURL

The App domain, in the production environment is the one that will be a registered domain with an entry made in to DNS. As of now your deployment adds a host entry like the ones below to enable viewing the app in your local farm.

SPHostedAppHostEntry

These steps made sure that my app gets deployed successfully!!

Before you browse your app, some browser level settings needs to be done.

  1. Add your app domain site to the Local Intranet Sites list. To do this go to IE -> Tools -> Internet Options -> Security -> Local intranet -> Sites & add http://*.appdomain.com (In my case it would be http://*.chanakya.com ).
  2. If you are in a corporate network and using a Proxy, add your address in exceptions list. To do this go to IE -> Tools -> Internet Options -> Connections -> Lan Settings -> Advanced & under Exceptions add *.appdomain.com.

SPHostedAppIESettings

Now you should be able to browse your app from the site you have deployed. In case your app prompts continuously for credentials, the last step you need to do is to disable the loopback check.

To disable loopback, open the registry and go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\LSA and create a new DWORD (32-bit) Value with a name of DisableLoopbackCheck and set the value to 1.  Restart the server after the change to ensure it takes effect.

And finally, you should be seeing your app loaded & the welcome message in the page.  Now you can start coding your app and just go on pressing the way old F5 to see the changes reflecting in your app :)

Do post if you face any other errors you come across in the comments section & Happy APPing :)


Customizing the SharePoint forms using Infopath is easy in SharePoint 2010. You have a “Customize Form” option under List Tools -> Lists in the ribbon when you are in the list view. Below screenshot shows that option (highlighted in red).

listview

On selecting this option, the form(Edit) is opened in Infopath Designer. Here you will be doing the changes in one infopath form(Edit) but, once you publish the form, the changes will be reflecting in all the three forms (New/Display/Edit).

So what if you want to edit three different forms in three different ways? Say New form should have all columns displayed, edit form should have some fields disabled where user cannot modify the values and display form having a different layout altogether.

Infopath solves this purpose by providing Views. We will be creating 3 views for each of the forms (New/Edit/Display). Follow the below steps to create separate views for each form.

  1. In the InfoPath designer, where your form is opened, , click on Page Design tab on the ribbon.
  2. You would be able to see the list of views available as a drop-down and also an option to create New View. You will be already having a view named Edit item (default) displayed in the drop-down.6581
  3. Already having a view for Edit form, we have to create 2 new views for New & Display. Click on New View.
  4. In the pop up opened type the name of the view(say Display Item) and click OK.
  5. Now you have an empty view, where you can add fields(from right side pane displaying fields from datasources), modify the layouts, adding rules, hiding columns. The changes you do in this view is going to affect only this view. If you want to replicate the views, just select all & copy the contents from one view & paste it in your new view.
  6. You can create another view (New Item) following the steps 3-5.
  7. Once you have created the views and done with your changes, publish the form.
  8. Now having 3 views for 3 different forms, you need to make your SharePoint list aware that which form to use which view.
  9. Open the list in SharePoint Designer, in the lists detail page, under Forms section, generally you will see DispForm.aspx, NewForm.aspx, EditForm.aspx. In addition to that since you have edited this list in infopath you will see 3 more forms namely displayifs.aspx, newifs.aspx & editifs.aspx.
  10. You need to set your views for each of this form. For each of the forms do the following steps.
  11. Open the form, select the form(highlighted in below snapshot), right click and select properties.6582
  12. In the properties window opened, under Misc header, set the DefaultView value to the view name you have created.
  13. You will be setting the values as below
    Form Name Default View Name
    displayifs.aspx Display Item
    editifs.aspx Edit item
    newifs.aspx New Item
  14. Now browse the list in IE to see different views set for different forms.