Pass parameter to Infopath 2007 browser forms using Business Data Catalog

Last week, I got an excellent oppurtunity to work with Infopath 2007 and Business Data Catalog(BDC). As per requirement, need to pass employee personal information id to infopath forms. Infopath form should pre-populate data from DB based on PersonalInfoID from Querystring.  Whether i pass a parameter to a form file in InfoPath 2007 or the Web browser, first i need to update the form template’s Loading event. The LoadingEventArgs class of the Loading event provides the InputParameters property. This property gets an IDictionary object, which contains any input parameters that are specified in the URL that is used to start a form file. Next, use the TryGetValue method of the IDictionary object that was returned by the InputParameters property to retrieve a parameter value. Then, use the SetValue method on an XPathNavigator object to set the corresponding node value in the form file. The following example sets the Employee Name box to the value based on PersonalInfoID parameter that was passed in the URL that was used to start the form.  public void FormEvents_Loading(object sender, LoadingEventArgs e) {

string personalInfoId = string.Empty;

try    

e.InputParameters.TryGetValue(“PersonalInfoID”, out personalInfoId);  

} catch (Exception ex) {

personalInfoId = ex.Message.ToString();

} finally {

 …do some db calls…

MainDataSource.CreateNavigator().SelectSingleNode (“/my:myFields/my: Name”, NamespaceManager).SetValue(customerId);

}

Next, I must update the Business Data Catalog metadata file to include a custom action. So I’ve added as follows, which adds a custom action to the existing Employee entity (before the </Entity> end tag) that starts the status report form in the Web browser with a PersonalInfoID parameter.

<Actions>   

    <Action Name=”Status Report” Position=”1″ IsOpenedInNewWindow=”true” Url=      “<i>My MOSS Server</i>/_layouts/formserver.aspx?xsnlocation=       /formservertemplates/statusreport.xsn&      openin=browser&PersonalInfoID={0}”>       

  <ActionParameters>           

                  <ActionParameter Name=”personalInfoID” Index=”0″/>       

    </ActionParameters>   

  </Action>

</Actions>

Now, if I would like to add save location(which user can save the form after submited to DB) as follows 

http://mossserver/Employee Info/HR Response/Credit Response/Check In/_layouts/FormServer.aspx?XsnLocation=http://mossserver/FormServerTemplates/StatusCheck-In.xsn&SaveLocation=http://mossserver/Employee Info/HR Response/Credit Response/Check In /Personal CheckIn&Source=http://mossserver/Employee Info/HR Response/Credit Response/Check In /Pages/default.aspx&DefaultItemOpen=1   - Kindly note that, I’ve long URL which more than675 characters. If we would like to add this URL into our custom action, BDC services turncated longest URL because of MaxLength.Now, how we can resolve this problem? – I got an idea, why don’t to apply URLMapping functionality to this scenario. So finally I’ve added URL Mapping element to Web.Config as follows:       <urlMappings>        

                  <add url=”~/sample.aspx” mappedUrl=”~/_layouts/FormServer.aspx?XsnLocation= /FormServerTemplates/StatusCheck-In.xsn&SaveLocation= /Personal CheckIn&Source= /Pages/default.aspx&DefaultItemOpen=1&Perso nalInfoID={0} ” />     

    </urlMappings> 

Ahrr….Finally, we solved the problem by adding URL mapping. Hatzz off to ASP.NET team J

Also, here’re some pointer really help me to solve this issue.

http://msdn2.microsoft.com/en-us/library/bb406004.aspx 

http://wm.microsoft.com/ms/msdn/office/2007officevisualhowtos/infopathparameters.wmv – Excellent videocast regarding this context 

4 Comments

  1. 1
    Bill Says:

    MSN I NIIPET
    MSN

  2. 2
    Sunil Joshi Says:

    Nice one !!

    I try using the above, but i want to open the infopath form in web-page mode.
    Does the above expirement support it,
    i m getting an error while opening the form …

    please revert back

  3. 3
    lovedjohnysmith Says:

    Sunil,

    Please have a look at the following URL:-
    http://wm.microsoft.com/ms/msdn/office/2007officevisualhowtos/infopathparameters.wmv

    Regards,
    Johnny

  4. 4
    Disha Says:

    Hello

    If it is not against ethics, can you please pass me the code or step by step instruction. I am also tryint to do this, but not able to fetch record from BDC datalist to Infpath forms.

    Please help me out
    Disha


RSS Feed for this entry

Leave a Comment