Wednesday, June 6, 2007

Pass parameters to InfoPath Form

In some cases it might be handy to pass some parameters to the InfoPath form. Example: It would be nice if users don't have to complete their account data (Name, Surname, E-mailadress,...). In this case you have a few options:

  1. Access SharePoint webservices to retreive the data (UserProfile.asmx)
  2. Write some code behind the InfoPath Form (as exposed below)
  3. By using Contact Selector ActiveX control

InfoPath codebehind method:

In the Loading event of the form template, we have to catch the parameters with the TryGetValue method.

public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
string Naam = string.Empty;
try
{
e.InputParameters.TryGetValue("naampje", out Naam);
}
catch (Exception ex)
{
Naam = ex.Message.ToString();
}

finally
{
MainDataSource.CreateNavigator().SelectSingleNode
("/my:myFields/my:voornaam", NamespaceManager).SetValue(Naam);
}
}


Afterwards, you can pass a parameter through the URL. Add a querystring at the back of the URL eg. &naampje=kieseennaam

No comments: