Thursday, September 26, 2013

Microsoft InfoPath - Best practices

After working extensively on InfoPath forms for so many years, I would like to share some of the best practices or techniques which I always keep in mind while creating a system using InfoPath forms.

InfoPath offers great deal of features while designing user forms; however, if the features are not used in an appropriate manner, it might confuse the end users; hence, we need to take care of few things in order to make the form appealing and simple. Here is the list:

1) Hide the top ribbon and create buttons on the form for submission and close

I always prefer to have two buttons - one for Submit and the other one for Close - on an InfoPath form rather than using the options on top ribbon. In most of the cases, the top ribbon is not that visible to the users, and it takes some time for them to understand how to close or submit the form. In order to avoid this confusion, hide the top ribbon and create simple buttons on the form.
You can hide the following top ribbon from the form options.

2) Form must close automatically after the submission

We should always make sure that the form is closed automatically once it has been submitted. I have noticed many times that a new form opens once the form is submitted by the user. It is confusing and irritating; hence, we should always take care while designing the form that it is closed after a user submits it and goes back to the page where you want to redirect the user.

In case of big projects and client facing sites, the best approach is to create a button on a SharePoint page and place the link of the form on that button by customizing it by giving a source parameter.

For example: If I have created a survey form using InfoPath, I would prefer creating a page on a SharePoint site with required Web Parts for the data presentation with an appropriate button for the form's link. However, I will add a source parameter to the link, so that instead of taking the users back to the library, it should take them back to the current page. Appending the form's link with the source parameter, you can control the redirection aspect of the form.

3) Should consider the situations after a form is submitted

Whenever a form is submitted, the next step is to understand the possible situations of dealing with the submitted forms. InfoPath forms give you more flexibility in terms of controlling the behavior. For example, you can always set a functionality where the person who submitted the form will only be allowed to edit it and no one else which is not that straight forward to achieve in terms of aspx forms.  There can be many scenarios:

a) Should we give the option for editing to the users?
b) Should the form be read only once it is submitted?
c) Other than the user, should any other person with higher authority should able to view the form?

We need to consider all the above situations and implement the functionality on the InfoPath forms accordingly. In case workflows are attached with the InfoPath form library, things are more difficult when it comes to implementing the functionality where we allow the users to update the forms later on.

4) Display proper messages for the validations

If a validation is true on any InfoPath form's field, it shows a red dotted line over that field; however, when you hover on that field, it displays the validation message. In all the scenarios, we should implement the functionality where the validation or error message is displayed below the field whenever any of the validations is true. In most of the situations, the user may not hover on the field; hence, without any message, they will not be able to understand the meaning of the red dotted line.

5) Limit the number of rules and validation

We should be very careful while writing the rules and validations for the form. Lot of rules and validations on a form can affect its performance and can make it slow. Every rule or validation triggers a post back event where a request to the server is made. In case, lot of requests are made at the same time to the server, the form may not show the expected behavior and might get crash.
Hence, we should try to implement only the most important and required rules & validations in order to normalize the form.

6) Limit the number of fields

In addition to the above point, we should also try to limit the number of fields on the form. The more the number of fields, the form will take more time to load; as a result, affecting the user's experience. Many times, I have heard people complaining regarding the inefficiency of InfoPath forms while loading. A simple fact: it is not always the fault of the software in terms of performance; a great deal of software's performance also depends on its implementation (apart from server's performance); hence, we should always strive to normalize the form in terms of rules, validations, and number of fields.

I hope you all enjoyed this article and learnt something from it. Thank you so much for spending your time and effort.

7) Uncheck "Automatically retrieve data when form is opened"

Always uncheck the above option while creating a data connection on the form. If you don t need to pull the data at the time of form load then it is a wise decision to uncheck the option and pull the data by creating queries and rules. At the time of form load, this option retrieves the entire data from the list or library where the data connection has been made; hence, it affects the performance of the form by unnecessarily pulling the data when you don t need it.

8) Follow proper naming conventions and documentation

Use proper naming conventions, especially in case of large and complex forms. In that case, it is very easy to manage the form in the long run. I always prefer to name fields on the form by separating the text by underscore. For example: In case I need to name a field for Employee Name, I write the name of the field or control as "Employee_Name".
Also, use proper documentation for the rules and validations on the form. We do have a "Rule inspector" option to check all the rules and validations on the form; however, nothing can beat a proper documentation as it is very helpful in maintaining the complex and large forms.

9) Use coding as the last option

We can achieve a lot by writing rules and validations; hence, coding should be preferred as a last option. If we need to achieve something complex which cannot be done using rules then we should go with the coding option as the rules are always executed first and then the code.

Tuesday, May 7, 2013

Using active directory group as a distribution list and for giving SharePoint access

Few weeks back, I was asked a question on how we can use an active directory group:

1) As a distribution list (DL) for sending emails via outlook.
2) For giving SharePoint site access to the members of that active directory group.

The requirement was to achieve the above mentioned things using a single active directory group. In other words, we wanted to use the same active directory group as a DL for sending emails to a number of people at one go and also to add them to a SharePoint site through one step instead of adding every person one by one.

Well, the answer was simple. The active directory groups are created at server machine. Whenever we create an active directory group, it gives us following group types:

1) Distribution list (DL)
2) Security

If we select DL then we can use that active directory security group as a DL only; however, if we select "Security" then we can use that group as a DL as well as for giving SharePoint access to the people in that group. Also, we need to specify the name of the administrator of that group, and only that person will be able to add and delete members. Whenever there is any change in the membership of an active directory security group by the administrator, the DL will be updated automatically as there will be a synchronization mechanism.

This was one of the best practices which we started following in all our projects, and it helped us in saving lot of time and effort.

Microsoft office OneNote application

I have to say that I am completely biased towards Microsoft OneNote. This is one of the great applications, and I am a huge fan of it. This made my life easy in managing all my professional as well as personal tasks. Also, it is very user friendly; especially for those who are quite familiar with Microsoft suite's other applications. I made it a best practice in my team to manage the work; however, the most disappointing factor is that this application is highly underrated, and most of the people do not know about its functionality. So let's see that how this application can help in managing your things.

Microsoft OneNote is a part of Microsoft Office suit 2010. It is a kind of place to store and manage all your notes in a collaborative manner. The term collaborative is very important because it lets you share your work and notes with other people in a very convenient way. In this article, I am going to cover the following points:

1) Accessing OneNote.
2) Create a notebook in OneNote
3) Different methods of sharing notebooks with others.
4) Integration with SharePoint and multiple people accessing it
5) Automatic synchronization mechanism
6) Unfilled notes feature

Accessing OneNote

To access OneNote, select Microsoft OneNote from the list of programs in Microsoft Office suit. You will be able to see the below view.

If you are opening OneNote for the first time, the left hand navigation will be more clean in the above image. By default, there will be two or three notebooks when you open OneNote for the first time. Yes, in the left hand navigation, you will be able to see all your notebooks at one go as shown on the left hand side.

Let's see one notebook in detail in the interim, and what all is included in a notebook. On the right hand side, it is an image of a notebook named as "Weekly task updates". All the colored folders in this notebook are known as sections. Within sections, you can create different pages as shown in below image. Pages and sections let you manage your data and information. For instance, in the current notebook, I am managing information by keeping it month wise. You can use your creativity in naming the sections and pages in any manner.

Create a notebook in OneNote

Here are the steps to create a notebook in OneNote:

1) Form the top ribbon, select "File".
2) From the left hand navigation, select "New" as shown in the below image.
3) First and foremost, it will ask that where do you want to store the notebook. I will explain the three options in the next section.
4) Once you have decided the location to store the notebook, click on "Create Notebook".

Sharing notebooks with others

If you have to share a notebook then follow the below steps:

Here is the explanation of storing options as shown in the above image:

1) Web: You can store your notebook on Skydrive, and for that, you need a Windows login ID. The biggest advantage of storing your notebook to Skydrive is its accessibility. I have OneNote app on my iPhone, and I  have synced all my notebooks on Skydrive with my iPhone. I can refer to them anytime and anywhere.

2) Network: You can share your notebook on SharePoint using this feature, and for that, you just need to mention the URL of the document library where you want to store your notebook. This is a great way to manage the information with your team members. Most of the times, I store all the meeting minutes in a shared notebook so that people just have to go to the document library to refer to them. Also, you can simply open the notebook in OneNote from the browser. Once the notebook opens in OneNote, it will synchronize the entire information automatically. You do not have to press any sync button as it will automatically sync all your notebooks with their shared locations once you open OneNote in your local machines.

3) My Computer: You can use this option to store notebooks in your local machines.

Integration with SharePoint and multiple people accessing it

As explained above, for integrating a notebook with SharePoint, you need to use the "Share" feature to share it in a SharePoint document library. You need to follow the above steps for sharing the notebook and need to mention the appropriate URL of a document library.

Point to note: In order to open a notebook in browser, we need to activate a site collection feature known as Office Web apps. Unless this feature is activated in SharePoint, notebook will not open in the browser.

The below notebook has been opened in a browser. Browser will not give you lot of features, and it will have very minimum features as compared to OneNote client applicaion. If you need to do some high formatting work then you can always open a notebook in OneNote from browser as shown in the below image. Also, the attachments will not be visible in the browser, so to see them, you need to open the notebook in OneNote.

Another great feature of OneNote is that multiple people can access it at the same time. Yes, multiple people can write on the same notebook simultaneously and all the changes will be synced automatically. Users do not need to press any save or sync button and all the changes will be saved automatically.

 I will be explaining the synchronization mechanism in the next section.

Automatic synchronization mechanism

As explained above, whatever you write on a notebook, it will automatically get sync with the file on server. So, if I make some changes in a notebook, and if I am sharing it with my team, they will see new changes in few minutes whenever they open OneNote on their local machines.
No matter how many people write, OneNote will keep on saving the changes automatically; and the file on the server will always be in sync. 

Unfiled notes feature

This is another cool feature of OneNote. Sometimes, we need to write things in haste when we are not sure on how to manage such information at that time. In that case, you can write your notes in Unfiled section.
The biggest advantage is that the moment you write something in Unfiled notes section, it will get save automatically. If after writing all the notes, your OneNote gets closed inadvertently, you will never have to worry as the entire information was saved automatically the moment you wrote it in Unfiled section.

There are lot more exciting features relating to OneNote, so I will keep on sharing the best practices.
Happy reading!!!!!

Sunday, September 9, 2012

Calculating day of the week in InfoPath without code

I love working on InfoPath. It is a very flexible tool which gives you wide range of options to design the functionality, that too without writing code. Last week, I came up with a requirement of calculating the day of the week from a particular date. For example, if the date selected in the date picker control is September 9, 2012, and the day of the week is Sunday on this day then I wanted a functionality that will give me the value "Sunday".

I researched about it, and fortunately, I found an interesting article which I would love to share with my readers. Just few simple steps, and it worked like a charm. On the form, put one date picker control and one text box field naming "Day of the Week". Create a rule, select the type as action, for the date picker control and set the field "Day of the Week" equal to the below formula:
(number(substring(Date, 9, 2)) + number(number(substring(Date, 1, 4)) - (floor((14 - number(substring(Date, 6, 2))) / 12))) + floor(number(number(substring(Date, 1, 4)) - (floor((14 - number(substring(Date, 6, 2))) / 12))) / 4) - floor(number(number(substring(Date, 1, 4)) - (floor((14 - number(substring(Date, 6, 2))) / 12))) / 100) + floor(number(number(substring(Date, 1, 4)) - (floor((14 - number(substring(Date, 6, 2))) / 12))) / 400) + floor((31 * number(number(substring(Date, 6, 2)) + 12 * (floor((14 - number(substring(Date, 6, 2))) / 12)) - 2)) / 12)) mod 7

It will return the following:
1) If the value returned in "Day of the Week" field is 0 then it is Sunday
2) If the value returned in "Day of the Week" field  is 1 then it is Monday
3) If the value returned in "Day of the Week" field is 2 then it is Tuesday
4) If the value returned in "Day of the Week" field is 3 then it is Wednesday
5) If the value returned in "Day of the Week" field is 4 then it is Thursday
6) If the value returned in "Day of the Week" field is 5 then it is Friday
7) If the value returned in "Day of the Week" field is 6 then it is Saturday

Now, create 7 rules for "Day of the Week" field to set the field's value to appropriate day when "Day of the Week" field is equal to above mentioned numbers.For example, set the first rule by specifying the condition that "If the Day of the Week field" is equal to 0 then set the value of Day of the Week field to Sunday, and in the same manner, create 6 other rules for the remaining days of the week.

Happy reading.

Monday, June 4, 2012

Copying SharePoint Designer workflows

Many times, I have seen people asking questions regrading copying SharePoint Designer(SPD) workflows. Once, I got a requirement of moving a SPD workflow in to another site collection. The workflow was a list workflow, and not a reusable workflow, in which case, there is a possibility of reusing the workflows in different lists. As it was a big workflow, I did not want to re-create it, and I started looking for options to move this workflow. One option, I thought was to take a list template and then creating a new list based on this template on the other site collection; but, the data on the list exceeded 10 MB, in which case, you cannot take the template of a list. I started researching about moving SPD workflows, and at last, I got a wonderful post, which I would like to share with everyone.

Nick Grattan wrote a beautiful post on Applying a SharePoint Designer workflows to multiple lists. He just explained in small steps that how a SPD workflow can be moved from one list to another.
You just have to copy the xoml and xoml.rules files from the source workflow to the target workflow. Once you finish copying the content of these files, close the entire SharePoint Designer. Make sure that both the lists have the same name of the fields which will be used in the workflows. For example, if you are using 10 fields in the source workflow then before copying it, make sure that the target list have the same name of the fields which are used in the source workflow. If this is not the case then the workflow will be copied, but you need to set the binding of the fields in all the conditions and actions in the target workflow. I tested it, and I was surprised to find that this trick worked like a charm in moving the workflows from one list to another list, which was located on some other server.

Happy reading everyone!

Tuesday, November 30, 2010

Auto Generating ID in Infopath (Without Code)

I have already discussed about how to generate an automatic ID in Infopath with the help of Programming. Well, many people are not very much familiar from writing code and they prefer a no code solution. So, I thought of explaining the same concept without code.

There are certain inbuilt functions in Infopath which many times save your hell lot of effort and also provides good flexibility to manage your applications. One of them is the "Count" function which, as the name suggests, count the number of items in the node. We will make use of this function to generate an ID.

Let us take the same example which I took in the last post to explain the same concept but with code. We have an Infopath form which we use to file the review meetings of the project every week. The submitted Infopath form is named in such a way that the name is the concatenation of the name of the Project and the next count. Like, If the Project name is "A" and already 5 items for this project are there in the list then the name of the next infopath form will be : A_6. Project name is entered by the user while filling the form. The number "6" is calculated with the help of the "Count" function in the Infopath form and let us see how.

Design the Infopath form by creating all the fields like Project Name, Today's Date etc. as per your requirements. Publish this Infopath form and make it as a content type in the form library. Then we need to make a receive data connection referring this Library and click the field "Project_Name" while making this connection as it will ask you to select the fields whose values you want to enter in the form. Now create a field in the Infopath form and name it "ItemsCount". Open the properties of this field and click the button just next to the place where you enter the default value. Select the "Count()" function and you will see that it will be asking you to enter a field from the form as a parameter. Click on that parameter and select the receive data connection you just created. It will show you the field "Project_Name" as while creating this connection, you clicked it. Select this field and instead of clicking the "Ok" button after that, just click the "Filter" button. Click on "Add" button and you will see three drop down boxes. Now select the "ProjectName" field of the Infopath form in the first drop down box. In the second drop down box, select "is equal to" and in the third drop down, select the receive data connection and in that select "Project_Name"(This is the field in the Form Library) . In short, we have written a query that will give us the count of the items in the form library where the project name is the one which is entered by the user. So if the user selected Project "A" in the Project Name field in Infopath then this will give us the count of the number of items where the Project name is "A" in the list.

Now create a new field and name it "ID". Open its properties and from the list of inbuilt functions, select "Concat()". This function is used for concatenation and by using this we will concatenate two fields. The default value of the ID field will be :
concat(ProjectName, "_", (ItemsCount + 1))

Here, ProjectName and ItemsCount are the field from the Infopath form. As you can see that we have added 1 to the ItemsCount function, so we will always get the next ID while submitting this form. Make the "ID" field as name of the submitted form and it will always give you the next number.
(I am so sorry for not giving the screenshots)..........

In my last post, I explained this same concept with a CODE solution. Well, the choice completely depends upon the application's requirements, its complexity and your ease. I use both the solutions depending on several factors. I prefer a no code solution when my application is simple and I just need to generate an ID. But if my application is complex and I am aware that further more requirements will be introduced then I go for a Code solution as it provides great flexibility to change your application. That is why I wrote two different posts to explain the same concept so that users can decide their option depending upon several factors.

If possible, please spend little time to poll or comment that whether this post was helpful to you or not. Your feedback matter a lot as that will enable me to improve the posts for my readers.

Friday, November 26, 2010

Auto Generating ID in Infopath (With Code)

Things would have been so easy if there would have been an autogenating ID feature in Infopath form library. To track the number of items, a column naming "ID" is there in every list but it does not serve any useful purpose when an item is deleted. This is because, it is not effected by the deletion of the items and keep counting them as and when the items are added. So if 5 items are added and you delete one of them, then the next count will be 6 only and not 5.
Well, things are not that much difficult and I figured out an easy solution to achieve this task. But with one condition and that is to use SharePoint Object Model. We will start this with an example as that will make things very clear.

Let us suppose that we are designing an Infopath form with programming and I am writing this code in the submit event handler. We have a scenario of calling meetings of a particular project by filling the Infopath form. Once the form is submitted, a mail goes to all the team members about the details of the meeting and the submit title of the form is "Project Name_Meetings Count". This means that if Project A is there and if I am filling its 5th meeting then the title will be "Project A_5". This value is generated automatically through code in the submit event handler and is then assigned to a field in the Infopath form. The most important thing over here is the count and lets see that how is this calculated.

We have a field in the Infopath form naming "Project Name" which the user enters while filling the form. When he submits the form, I run a CAML Query to calculate the count of the items, having the name of the Project specified by the person in the form. Then this count is added by one to calculate the next ID and this ID is then assigned to the Infopath field "SubmitName" which is the name of the submitted form.

//First Retrieving the value entered by the User
XPathNavigator MyNavigator = MainDataSource.CreateNavigator();
string ProjName = MyNavigator.SelectSingleNode("//my:ProjectName", NameSpaceManager).Value;

SPWeb MyWeb = null;
using SPSecurity.RunwithElevatedPrivilidges(delegate ()
using(SPSite MySite = new MySite("Your site URL"))
MyWeb = MySite.OpenWeb();

//Retrieving the List
SPList MyList = MyWeb.GetList("Your List URL");
string FieldIntName = MyList.Fields["Project Name"].InternalName.ToString();

//Running CAML Query to get the count of the Project Name entered by the User.
SPQuery MyQuery = new SPQuery();

In the Field Ref, you need to write "FieldIntName", which is the Internal Name of the Project name and this is a column in the list.
In the Value, you need to write "ProjName", which is the name of the Project entered by the user while filling the form.

//Fetching all the items satisfying the above query.
SPListItemCollection AllItems = MyList.GetItems(MyQuery);
int Count = AllItems.Count; //This gives us the count of the items having the project name entered by the user.

In order to create a new ID, we will add one to the total count and will concatenate this ID with the Project Name. So like this, our ID will automatically be generated every time a new item is added. And, it will not be affected with the deletion of items as the count is calculated on the basis of items added in the list.

//Final ID will be :
string SubmitID = ProjName + "_" + (Count + 1);

//Assign this to the field in the infopath form which will be the name of the submitted form
XPathNavigator formNav = MainDataSource.CreateNavigator;
formNav.SelectSingleNode("//my:SubmitName", NameSpaceManager).SetValue(SubmitID);

Now when the form is submitted, a CAML query is run to calculate the count. And then, one is added to the total count to generate the next ID.

The same thing can be done without programming also which I will be explaining in my next post. I know that you all must be wondering that if this is possible without programming then why to go for a programming option. Well, the answer is that the programming option gives you great flexibility and you can further customize your application depending upon the requirements. I use both the options depending upon the complexity of my task. If i just need to generate an ID then I go with no code solution. But if I have to do several other complex tasks then I go with programming option. Always, the choice is your.