Saturday, July 28, 2012

Toggle section from within InfoPath form

A simple way to add section toggle from within InfoPath form.
Step for creating form -

Add a new Field - HideShowButtonText, set default value to "t" without quotes

  Steps for adding button -

1. Add new button, Set the button ID to "btnToggle"



2. Set the Label to HideShowButtonText field we created earlier
3. Right Click on the Button and open "Borders and Shading"
4. On Border tab - change Presets to None
5. Click on Shading tab and select No Color then click "OK"
6. Now while your button is selected, change the button text font to "Wingdings 3" and text size to 10


Setting Rules -

1. Double click button
2. Click on Rules...
3. Click Add...
4. Rename Rule 1 to Show Section Rule
5. Click on Set Condition...
6. From field list dropdown pick HideShowButtonText field
7. Select the condition to "is equal to" and set the value part "t" again without quotes
8. Click "OK"
9. Click on "Add Action..." and pick "Set a field's value" from Action dropdown
10. Set the field to HideShowButtonText and Value to "q" without quotes
11. Make sure to check on "Stop processing rules when this rule finishes
12. Add another rule - "Hide Section Rule" as above and this time set HideShowButtonText field to "t" and allow this rule to run when HideShowButtonText = "q"

Section Toggle -

1. Right click any section on your Form which you want to hide or show based on btnToggle button clicks
2. Select "Conditional Formatting..."
3. Set the condition to HideShowButtonText is equal to "t" and make sure to check on "Hide this control"


That’s it we are done with all the required changes now click on Preview and see how you can hide and show section(s) from within InfoPath form.

Feel free to download sample Togglesection.xsn file

Friday, June 22, 2012

Problem with setting field's internal name with AddFieldAsXml


If you are trying to Add fields to a SharePoint list using AddFieldAsXml method with Client Side Object model you might be doing something as below -

using (ClientContext ctx = new ClientContext("http://opc-ad-devspw1/sites/devenf/wb2/%22))
{
       Web web = ctx.Web;
       FieldCollection flds = web.Lists.GetByTitle("MyList").Fields;
       ctx.Load(flds);
                flds.AddFieldAsXml("<Field DisplayName='My Field' Name='MyField' Type='Boolean' />", true, AddFieldOptions.AddFieldToDefaultView);
                ctx.ExecuteQuery();
}

I ran into a problem were my field was getting added, but my internal name was being set to “My_x0020_Field” discarding my Name property.  Finally, after little bit of research I found out that to set field’s internal name with AddFieldAsXml you need to use AddFieldOptions.AddFieldInternalNameHint. 

check here - http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spaddfieldoptions.aspx

flds.AddFieldAsXml("<Field DisplayName='My Field' Name='MyField' Type='Boolean' />", true, AddFieldOptions.AddFieldInternalNameHint);

Using AddFieldInternalNameHint fixed my problem and it's not a bug.