Archive for the ‘InfoPath2010’ Category

Customize SharePoint list using InfoPath2010 form Part4

March 5, 2012 3 comments

Customize SharePoint list using InfoPath2010 form Part1

Customize SharePoint list using InfoPath2010 form Part2

Customize SharePoint list using InfoPath2010 form Part3

In this post, I’d like to show you how to create print functionality in InfoPath for SharePoint list. The print functionality is provided out of box in InfoPath form library; however it is not available in SharePoint list. Here are the steps to create the print functionality.You can download the new form here.

1. Create print page in the list by first copy and paste the displayifs.aspx and rename the file to Printifs.aspx.

2. Open the page in the SharePoint designer and copy the following javascript to the PlaceHolderTitleAreaClass ContentPlaceHolder.

//You need to refernces jQuery to make the following code work.
//Alternatively , you can only use window.print(); and use css to format the form to print.
<script type="text/javascript">






$("[id='s4-titlerow']").css("height", "0px");

$("body").css("background-color", "white");

$("body").css("zoom", "135%");

$("[id='MSO_ContentTable']").css("margin-left", "0px");

$("[id='MT-BodyContent']").css("width", "900px");

$(".MT-BodyArea").css("width", "900px");

$("[id='MT-Layout']").css("width", "900px");

$(".ms-bodyareacell").css("width", "900px");

$(".s4-wpTopTable").css("border", "none");

$("[id$='XmlFormView']").css("margin-left", "-80px");

$("body").css("margin-top", "-30px");

$(":contains('ybbest')").css("border", "5px solid #FFCC00");



3. Open InfoPath form for the list and create a field called PrintLink

4. Set the default value of printLink that points to the print page I just created before with the query string id.You can download the formula for the default value here.

5. Add a new image that looks like Print button on the display view, then I can set the url to the Print link Field. (The reason I did not use button is that you cannot set the navigate url for the button).

6.Set the url of the image to the PrintLInk field.

7.Next , create the print view.

8. Copy the contents from the display view to print view

9. Finally, go to the printifs.aspx and edit the InfoPath web part to set the view to PrintView.

9. Republish you form you will see the form as shown below

10. If you click the Print button, you will see the print page and print dialog,you can also add the company logo in the print page using css as well.

11.To deploy the customization,you can use the backup and restore content database approach , you can get more details from my previous blog post here.


Customize SharePoint list using InfoPath2010 form Part3

February 26, 2012 Leave a comment

Customize SharePoint list using InfoPath2010 form Part1

Customize SharePoint list using InfoPath2010 form Part2

Customize SharePoint list using InfoPath2010 form Part4

In the part 2 of this series, I have showed you how to create a display view. In this post, I will show you how to create a calculate field for multiple selection box using double eval.

1. I am adding another field in Employee list called skills which allow multiple selections. You can download an updated project here.You can download the formula in a text file here

2. Because Skills field allows multiple selections, you need to use double eval to create the calculate field.Copy eval(eval(Value, ‘concat(., “; “)’), “..”) To the Formula and replace Value with the field value

3. Republish your form and you will see the display form looks like below

4.If you like to remove the trailing ;, you need to change your formula to substring(eval(eval(Value, ‘concat(., “; “)’), “..”), 1, string-length(eval(eval(Value, ‘concat(., “; “)’), “..”)) – 2)


Customize SharePoint list using InfoPath2010 form Part2

February 26, 2012 Leave a comment

Customize SharePoint list using InfoPath2010 form Part1

Customize SharePoint list using InfoPath2010 form Part3

Customize SharePoint list using InfoPath2010 form Part4

In the last post, I have shown you how to customize SharePoint list using InfoPath , in this post I will continue where I left off to show you how to create different views for each form.(edit form and display form)

1. Go to Page Design view and click the New View called DisplayView

2. Create the form like shown below by first inserting a table and then drag the following fields to the table. However, as you can see that it displays input control like textbox and dropdown list. In the display view, we would like to show only the values of the fields rather than take input from the users. I will clean it up in the following steps.

3. Now, delete the input controls and drag a calculated value control from control sections in the home tab

4. Insert the calculated value by selecting the FX

5. Select each field from the fields selection.

6. After you have completed the above steps , you will see the view shown below.

7. Publish the new form and go to the employee list and click the Form Web Parts and select (Employee) Display Form

8. Edit the InfoPath form web part and select the DisplayView

9. Click save and open an item, you will see the display view shown below. However , you will notice that instead of displaying HR for Department Name it displays 2.This is because Department Name is a lookup field , you need to grab the value from the second data source in InfoPath. I will show you the steps next.

10. Right click the calculated field and select the Calculate Value Properties

11.Edit the formula by selecting the fx.

12.Delete the existing formula and click Insert Field or Group

13. Select the Show advanced view and change from Main to Department(Secondary) from the dropdown list.

14 Select the Title from the dataFields and then click Filter Data.

15. Select the Department Name from the Main Data source for the first field.

16. Select the ID from the Department(Secondary) data source.

17. Republish your form, you might get the following errors, just ignore it.

18. After the form is published, you can see the correct information on the form shown below


Comparing SharePoint List and Form Library Forms

SharePoint 2010 – Set default value for a lookup column using InfoPath and no code

How to create initiation form for SharePoint2010 workflow part2

February 5, 2012 1 comment

In the last post, I have shown you how to create initiation form. In this post I will show you how to create the same initiation form using InfoPath. You can download the complete solution here.

1. Create an empty form using InfoPath2010

2. Add the a label, textbox and a button to the form

3. Add the following rules to the Start workflow button.

a. Add a Submit data action

b. click the add button and add a new connection

c. Choose the “To the hosting environment, such as an ASP.NET page or a hosting application.

d. Click OK to add the submit data connection.

e. Add the close form action and you are done with the rules.

4. Publish the form to the network and deploy the form to the SharePoint. You can find the details instructions in my previous blog.

5. You need export the InfoPath form and generate the code to get the data from the form.

a.Go to File >> Publish >> Export Source Files

b. Open visual studio Command prompt

c. Run the following command to generate the code:

xsd mychema.xsd /c /l:cs

6.Add the myfields.cs to the project under workflow node.

7. Modify the elemets.xml file in your custom workflow, as below.

8. You can get the FormURN by going to File >> Form Info >> Form template properties and the ID field is the current form URN.

9. Now, go to your workflow designer and bind your History description to a new property.

10.In the workflow activated event handler , write the following code.

11. Deploy your solution and invoke the workflow and you will see the InfoPath form Initiation Form

Populate people picker with current user in InfoPath2010

January 25, 2012 1 comment

In recent project, we have a requirement to populate people picker with current user in InfoPath2010 form. It is quite easy to do it in InfoPath; however it does not quite work as we have expected. In the end, we have to use a combination of InfoPath and list event receiver to complete this task. Here are the steps to set the current user to the additional stakeholder display name in InfoPath.

1. Add a set a field’s value rule to InfoPath Form load event.

2. Set the condition as below

3. Configure the set field value action as below, userName() is a built-in function in InfoPath2010

4. Publish the form, you will see the current user is populated with the current user name as below, however when you click the save, the user does not get saved. I guess this is due to the fact the people-picker control needs to perform a post-back to do some tricks.But we could not force the control to do it in InfoPath2010 for the automatically populated user , therefore we have to write up an list event receiver to set the current user.

5. In you SharePoint solution, add event receiver.

6. Copy the code to as specified to the screenshot

       public override void ItemAdding(SPItemEventProperties properties)

            string keyStakeholders = "Key_x0020_Stakeholders";
                // this has to be the static or internal name , not the display name

            string seperator = ";#";

            SPUser user = properties.Web.CurrentUser;

            if (string.IsNullOrEmpty(SPHelper.SafeToString(properties.AfterProperties[keyStakeholders])))
                properties.AfterProperties[keyStakeholders] = seperator + user.ID + seperator + user.Name;

                SPFieldUserValue fieldValue = SPHelper.GetSPFieldUserValue(SPContext.Current.Web,

                properties.AfterProperties[keyStakeholders] = seperator + fieldValue.LookupId + seperator +
                                                              fieldValue.LookupValue + seperator + user.ID + seperator +

7. Go to the elements.xml under the new event receiver

8. Change the xml highlighted in yellow



 9. Deploy your solution; it will work like a charm. 🙂


How to: Create an Event Receiver for a Specific List Instance

Create a “Save and Create New Item” functionality in InfoPath2010 Part2

January 25, 2012 Leave a comment

In the last post, I showed you how to configure the form to enable “Save and Create New Item” using Infopath2010. In this post, I will show you some of the problems and solution with enabling this in the form. Once you have enabled this function in the submit option, the save button in the InfoPath top menu will have the same functionalities, this might be confusing to the user as it will work differently from other forms.

To fix it, you can hide save button at the top ribbon and create a new button on the form called “Save And Close Form”. Here are the steps:

1. Go to File–> Advanced form options –>Web Browser and then untick the “Show InfoPath commands in Ribbon or toolbar”

2. Drag a button and label the button as Save and close the form in the InfoPath form

3. Add the following rules to the newly created button. Submit data rule and close form rule.

4. Republish your form and you will see the form as below.

Categories: InfoPath2010

Create a “Save and Create New Item” functionality in InfoPath2010

January 18, 2012 Leave a comment

Recently, I got a requirement to create a button on the InfoPath2010 form that save the current item and then open a new form so that they can add another item. To do so in InfoPath2010 is quite easy, here are the steps:

1. Drop a button at the bottom of the form and label it as save and add another Item

2. Right-click the button and select Button Properties.

3. Select Submit from the Action dropdown list.

4. Click the Submit Options and click the Advanced button.

5. Select “Open a new form” from the “after submit” dropdown list.

6. Republish your form, it works like a charm. This option is also available from the form submit options for the Save button in the ribbon.