Friday, March 19, 2010

Error 5337 when Submitting Data from InfoPath 2007 to a SharePoint List

There might be two reasons:-

1. security issue

In infopath editor, Go to form option, set full trust and create trusted certificate. That should make it work.

2. If you are using RunWithElevatedPrivilages or updating list

This happens mostly when you call SPListItem.Update inside the RunWithElevatedPrivileges block. So you should

•Declare your SPWeb object outside elevated block.
•Get SPWeb object inside elevated block.
•Use & Dispose SPWeb object outside elevated block

SPWeb myWeb = null;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite mySite = new SPSite("URL"))
{
myWeb = mySite.RootWeb;
}
});
myWeb.AllowUnSafeUpdates = true;
// using myWeb object access your list item, call update method on SPListItem
myWeb.AllowUnSafeUpdates = false;
myWeb.Dispose();

=========================================================

Error 5337 when submitting the form

There might be two reasons:-

1. security issue

In infopath editor, Go to form option, set full trust and create trusted certificate. That should make it work.

2. If you are using RunWithElevatedPrivilages or updating list

This happens mostly when you call SPListItem.Update inside the RunWithElevatedPrivileges block. So you should

•Declare your SPWeb object outside elevated block.
•Get SPWeb object inside elevated block.
•Use & Dispose SPWeb object outside elevated block

SPWeb myWeb = null;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite mySite = new SPSite("URL"))
{
myWeb = mySite.RootWeb;
}
});
myWeb.AllowUnSafeUpdates = true;
// using myWeb object access your list item, call update method on SPListItem
myWeb.AllowUnSafeUpdates = false;
myWeb.Dispose();

===========================================================================

Tuesday, March 16, 2010

How to Pass / access Parameters into an InfoPath Form

Parameters passed into an InfoPath form template or form, are available during the Loading event as a read-only collection of name/value pairs. In order to access these parameters you will need to write code that reads from this collection. This example uses C# and the InfoPath 2007 managed object model. Syntax for the legacy models follows. The steps below outline how to add code that access the Input Parameters passed into a form.

In the InfoPath designer, click on Tools menu -> Programming menu item.
In the fly-out menu select the Loading event (will be On Load in older InfoPath versions).
This will launch the appropriate IDE (MSE or VSTA or the Visual Studio Toolkit) with the code spit for the loading event inserted.
Add the following code to access the input parameters ‘ID and ‘Status' used in the examples above

(example is in C# using InfoPath 2007 Managed Object Model)
public void FormEvents_Loading(object sender, LoadingEventArgs e)
{

try
{

if (HttpContext.Current != null)
{
if (HttpContext.Current.Request.QueryString.Count > 0)
{
string strTempId = HttpContext.Current.Request.QueryString["ID"];
CreateNavigator().SelectSingleNode("/my:myFields/my:RequestTitle", NamespaceManager).SetValue (strTempId);
}
}
}
catch (Exception ex)
{
//Write exception code

}
}

moving a SPD workflow to production server

moving a SPD workflow to production server

There are several options for migrating the SPD workflow:

1. Recreate the workflow in the new server: this option has the highest probability for success since the list options are picked specifically for the new environment but this is also the most time con-suming option.
2. Perform a Stsadm Backup/Restore: this option works well but is harder to incorporate when you have an existing site. The overwrite options could cause issues so this option should be deployed to a new location.
3. Create a site template file: the workflow may not work after deployment.
4. Contend deployment can be used to move workflows. This is the most attractive solution for moving SharePoint Designer created workflows.
The links below will give you an understanding as to what content deployment is and how to plan for it:
http://blogs.msdn.com/sharepoint/archive/2006/05/02/588140.aspx
http://technet.microsoft.com/en-us/library/cc263428.aspx
Once you have content deployment setup you need to do to run a job to migrate a SPD workflow. For the Deployment Options you can use Deploy only new, changed, or deleted content.
Hope it can help you.

Re-parenting a SharePoint Designer workflow to a different list

This will allow you to package a workflow up as a feature and deploy and use it in multiple locations in your farm. However for simple deploy-ments you may want to stick with SharePoint Designer, if you do – read on!

Within the same site:
So you've got a workflow and now you want to either move it to another list or attach it to another list at the same time. The list you want to attach it to is in the same site. You would think there was a way of associated a workflow with more than one list but in fact there isn't and to some degree it's understandable. A lot of the actions you define in the workflow are specific to the library you are working with, even if you were to abstract your logic away from the list then SharePoint Designer links actions such as "Current Item" properties to the underlying list.
So, unfortunately it's not as easy as just editing the configuration XML file:
[workflow name].xoml.wfconfig.xml
and pointing it at the XOML and RULES files for your existing workflow. Your workflow will almost certain-ly contain references to the original library or list, so just pointing the config file at you existing workflow will have some pretty uncertain outcomes!
The good news is that you can use a lot of what you've already created and apply it to a new workflow, as per…
1.Make sure the new list your working with is set up correctly (content types, columns, approval, check in /out…)
2.In SharePoint Designer, create a blank workflow with a dummy step defined
3.Copy the contents of your original XOML file named, [workflow name].xoml to the new XOML file that was created when you created the new workflow (use notepad) NOTE: The XOML contains all the variables and activity definitions for your workflow, but not the logic
4.Copy the rules [workflow name].xoml.rules file contents to the new rules file NOTE: The rules file con-tains the login for if, then…else comparisons
5.Compare your config [workflow name].xoml.wfconfig.xml file with the original config file and make relevant changes (probably just need to reference the content types created when requesting data from users)
6.Check through the workflow and change any fields linked back to the original document library – THIS IS THE MOST LABORIOUS JOB!
• UPDATE…ACTUALLY IT'S QUICKER AND EASIER TO OPEN THE XOML AND DO A GLOBAL SEARCH AND REPLACE LOOKING FOR THE GUID OF THE ORIGINAL LIBRARY AND REPLACING THAT WITH THE GUID OF YOUR NEW LIBRARY (GET THE GUID FROM THE URL LINKS ON THE SETTINGS PAGES, THE "AUDIENCE TARGETING SETTING' LINK IS PARTICULARLY HELPFUL!)

To a different site:

Your workflow is great and now everyone wants a go! You need to deploy not just within the same site but to another location in your farm
The steps here are similar to the above, with the exception that you will have to copy all the files that are re-quired to run the original workflow to the new location. These files are usually just the ASPX pages that are run when you collect data from a user, you'll need to change the config file to associate the workflow with the files in the new location. Better still copy the files to a central location and reference them this location in both workflow's. That way you only have one set of files to keep up to date.
After you've done this you can follow the steps above to make the necessary changes.
Neither of these approaches is really ideal and to be honest there should be tools to make this process eas-ier, you can kind of see from the structure here that there is an app waiting to be written for this and if I have the time maybe I'll put one together. In the meantime please feel free to comment if you know of a simpler method.

Porting SharePoint Designer Workflows to Visual Studio

In reali-ty, an SPD workflow is a Workflow Foundation XOML file that’s compiled on the fly, so this file can be opened in the Visual Studio Extensions for WF. Today, I’ll show you how to get started;).
I’d strongly recommend having a basic understanding of how VS workflows work prior to reading this. For general information about building VS workflows, the SharePoint blog is a good place to start.


Step 1: Create a VS Workflow Project
In VS, go to File > New and select either a SharePoint Workflow Project (from the WSS or MOSS SDKs) or Workflow Foundation project. You will need Visual Studio Extensions for Workflow Foundation installed.

Step 2: Copy the SPD .xoml and .rules files into the VS project

With the new project in place, we’ll start porting the SPD xoml over to VS. First we need to extract the appropriate workflow files from SPD. To do this, open SPD and go to the Folder List. Right-click on the workflow that you want and choose the Publish Selected Files... option.
In the Remote Web Site tab of the dialog that appears, select the File System radio button and choose a local location on your com-puter. This will create a folder called Workflows on your file system in the location specified.
When you have these files, rename the .rules file (if you have one) from *.xoml.rules to *.rules. Then add the .xoml and .rules files to your VS project. If you double click on the .xoml file in the Solution Explorer, the WF workflow designer should open, and you should see all your SPD actions in place.

Step 3: Generate a .cs file under the XOML (optional)

If you want to add code behind your XOML, you’ll need a .cs file to go with it. By default, the copied XOML won’t come with this. To generate one, just bind a function to one of the activities in the designer. OnWorkflowActivated is there by default, so try typing an event handler name to its Invoke property. The .cs file created should automatically initialize the namespace and class name to match your XOML. If you don’t like the default names, change the attributes in the first line of the XOML in an XML editor before generating the file:


Step 4: Deploy and debug the workflow

Fill out the rest of your deployment files and deploy the template as a SharePoint Feature the same way as with any VS workflow, then associate it for use. Since SPD workflows weren’t designed to be ported over, expect some kinks that you’ll have to debug through. But hopefully, the workflow provides enough of a base there to work through them, and with the ability to code, you can find some nifty workarounds;).


References:-
http://blogs.msdn.com/sharepointdesigner/archive/2007/07/06/porting-sharepoint-designer-workflows-to-visual-studio.aspx
http://vspug.com/andynoon/2007/09/18/reparenting-a-workflow-to-a-different-list/
http://sanketinfo.wordpress.com/2009/05/05/limitation-of-sharepoint-designerspd-workflow/

Limitation of SharePoint Designer(SPD) Workflow

SharePoint Designer is good tool to start initial or basic level workflow, I am not expert and good person to point out any limitation into any software, but as per me below are some of the limitation which I felt for SharePoint Designer Workflow, I’ll also write you more description about some of the limitation in coming posts …

1.We don’t have facility to send BCC email to any person from “Send an Email” actions.
2.We can’t bind and attach more then one list into designer workflow, though there are some manual steps from where we can fulfill our requirements, but there won’t be any easy steps from interface or GUI
3.We can’t deploy/copy our designer workflow from one server to another server like there won’t be any easy way to deploy SPD workflow from development machine to TEST and Production Server; I’ll write how to do manual steps to achieve this functionality. here is my post regarding how to deploy designer workflow …
4.Designer Workflow don’t give us full customized editor from where we can customized our email body text, to do this, we need to write static HTML tags into email body part.
5.We don’t write any calculation fields or formulas into Designer Workflow actions items, like I can’t extract only date from date-time column into designer workflow interface, for this I need to take one extra column into my SharePoint list and need to manipulate into designer workflow.
6.While working in “Send an Email” action, if we add any list column from adding “Add Lookup to Body” button and if that column don’t have any values into SharePoint list, then it’s shows as ?????? instead of blank values into email body while sending emails …

Monday, March 15, 2010

Implementation of People Picker in Web parts

1. Introduction

There can be applications where we may need to add people or group to a share point list. For example, there can be a list which stores the meeting details. The meeting details include meeting name, meeting date and time, attendees, meeting facilitator, etc. In this case the attendees and meeting facilitator are of the type people or group.
People Picker is control through which we can add people or group in a share point application. The people picker control is available inbuilt when we operate through out of box for adding/editing people or group in share point lists. But, when the requirement is to include a people picker in web part, then there are certain properties and methods to be defined.
In this paper, the different sections discussed are:
· Declaring and assigning properties to a people picker control.
· Obtaining the properties of value added in the control (like display name, email ID)
· Clearing the values in a control.
· Updating the list item with the values in the people picker control.
· Populating the values to a people picker control from the list.

2. Declaration and assigning properties to People Picker.

The first step for including a people picker in a web part would be to declare an object for this control. This section discusses about the declaration and assigning properties to a people picker control. The people picker is enabled through a class called PeopleEditor. The declaration of PeopleEditor is as follows:
//Class definitions to be included for enhancing People Picker
using System. Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.Portal.UserProfiles;
using Microsoft.SharePoint.Portal.Topology;
using Microsoft.SharePoint.Portal;
//Declaring PeopleEditor object
PeopleEditor ctrlpplPicker = new PeopleEditor ();
//Defining properties of the PeopleEditor
ctrlpplPicker.AutoPostBack = false;
ctrlpplPicker.PlaceButtonsUnderEntityEditor = true;
ctrlpplPicker.ID = "pplEditor";
ctrlpplPicker.AllowEmpty = false;
ctrlpplPicker.SelectionSet = "User, DL, SecGroup, SPGroup";
ctrlpplPicker.MultiSelect = true;
ctrlpplPicker.MaximumEntities = 5;
The AutoPostBack property makes a page refresh on addition of value. It is assigned to false in order to avoid page refreshing.
The PlaceButtonsUnderEntityEditor property decides the location of the Names and Browse buttons of the people picker. If you set it to true, the buttons are placed at the bottom right corner of the account name text box, otherwise to the right of it.
The AllowEmpty property lets you define if the user is required to fill in a value in the people picker.
The SelectionSet property allows you to define the set of users and groups the people picker can choose from. This set can consist of users, Active Directory distribution lists, Active Directory security groups, and SharePoint groups.
The MultiSelect property lets you define if a user is allowed to specify multiple user accounts.
The Maximum Entities property restricts the maximum number of people or groups to be added to the control.

3. Obtaining details of the entries added in the people picker

Once the people picker control is added in a webpart, the next task would be to resolve the entries made, obtain the details of the entries (like display name, email ID) and update those details to the list. The below function explains about obtaining details of the entries made in the people picker.
// pplInfo is a string array which is used to hold display name and the email ID of the entries.
//Declaring pplInfo
String[] pplInfo = new String[2];
pplInfo[0] = String.Empty;
pplInfo[1] = String.Empty;
// objEntity is an object of Picker Entity class which stores the individual entry (people or group) added in the people picker control. This object is required to obtain the details of the people or group added in the control. objPplEditor.ResolvedEntities is a property of Picker Entity which resolves the entries made in the people picker control.
//The below for loop gets the count of number of entries made in the people picker. For every entry made, pplInfo [0] stores DisplayName and pplInfo [1] stores email ID.
for(int i = 0; i <>
{
PickerEntity objEntity = (PickerEntity) objPplEditor.ResolvedEntities[i];
pplInfo [0] += objEntity.EntityData["DisplayName"] + ";";
pplInfo [1] += objEntity.EntityData["Email"] + ";";
}
if (pplInfo[0] != String.Empty)
{
pplInfo[0] = pplInfo[0].Substring(0, pplInfo[0].Length - 1);
pplInfo[1] = pplInfo[1].Substring(0, pplInfo[1].Length - 1);
}
From the above coding snippet, the string array pplInfo holds the DisplayName and email ID of the entries made.

4. Updating people picker control values to a list item

Now we have the display name and the email ID of the entries made in people picker control in a string array pplInfo (pplInfo [0] stores Display Name and pplInfo [1] stores email ID). These values can be used to store display name and email ID in the list item.
//Open the share point site which contains the list in which the entities of the people picker is to be updated.
SPWeb myweb = new SPSite(siteName).OpenWeb();
//Get the list name from the share point site. mylist is a SPList object which points to the sharepoint list in the site.
SPList mylist = myweb.Lists[listName];
// ‘newitem’ is a SPListItem object which points to new list item to be added to the list.
SPListItem newitem = mylist.Items.Add();
//The display name and Email ID of the values entered in people picker control are updated to the list as shown below. Update () is the function which is used to update the list item.
newitem[columnName_DisplayName] = pplInfo[0];//Display name
newitem[columnName_EmailID] = pplInfo[1];//Email ID
newitem.Update( );

5. Clearing existing entities in the control

Once the control values are updated to the list we need to clear the control. The people editor control has property Entities.Clear( ) which clears the entries made in people picker.
ctrlpplPicker.Entities.Clear();

6. Populating values to control from the list

There can be a requirement where we need obtain the details of a list item from the sharepoint list and populate the obtained values to corresponding controls for viewing or editing. For example, in the case of meeting details, the attendees will be populated to people picker control, meeting name to textbox control, etc. The below section explains how the values are obtained from the list and populated to the control.
// The string variable pplNames_List holds the display names on getting the values from the list. Every display name is separated by semi-colon (;). For example, the display names obtained from the list will be of the form Sachin (WT-01 TIS); Edwin (WT-01 Retail).
string pplNames_List= "";
pplNames_List= master[columnName_DisplayName].ToString();
// pplNames holds the display name on resolving entities pplNames_List separated by semi-colon
string[] pplNames;
pplNames = pplNames_List.Split(';');
//Array list holds the complete list of names to be added to the control. The People Editor has a property UpdateEntities which populates the control with the values in Array List.
System.Collections.ArrayList pplList = new System.Collections.ArrayList();
// For every value present in the pplNames, the PickerEntity object ‘entity’ holds the value and entity is added to pplList.
for (int pplCounter = 0; pplCounter <>
{
PickerEntity entity = new PickerEntity();
entity.Key = pplNames[pplCounter];
pplList.Add(entity);
}
//At the end of this for loop, the Array list pplList will hold all the values retrieved from the list item for populating the control.
//The PeopleEditor has a property UpdateEntities( ArrayList ) which populates the people picker control with the values stored in the array list.
ctrlpplPicker.UpdateEntities(pplList);

7. References

A. MSDN site which contains PeopleEditor class
http://msdn2.microsoft.com/en-us/library/ms468579.aspx
B. Explanation for PeopleEditor properties and methods. Function for resolving entities.
http://www.lcbridge.nl/vision/2007/peoplepicker.htm

Author:- Avinash Kumar Dad
Location: Hyderabad, India