in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

Blog for Sharepoint Hunter

A (un)managed bag of ideas, tricks, gripes about New Emerging Technologies

Pass parameter (Custom Long Url) to Infopath 2007 browser forms using BDC Custom Actions

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&EmployeeID={0}&DeptID={1}&ContactInfoID={2}&LocationID={3}&CaseID={4}&StatusId={5}   - Kindly note that, I’ve long URL which more than 675 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=http://mossserver/FormServerTemplates/StatusCheck-In.xsn&SaveLocation=~/Employee Info/HR Response/Credit Response/Check In /Personal CheckIn&Source=~/Employee Info/HR Response/Credit Response/Check In /Pages/default.aspx&DefaultItemOpen=1&EmployeeID={0}&DeptID={1}&ContactInfoID={2}&LocationID={3}&CaseID={4}&StatusId={5} " />     

    </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 

Published Jul 12 2007, 08:46 PM by LovedJohnySmith
Filed under:

Comments

 

Cheryll said:

Excellent Post! - Helped us to choose an excellent tool for Application Definition file for BDC applications

July 12, 2007 9:09 PM
 

Mike G said:

Instead of "…do some db calls…", I'd like to query a SP list (likely via an XML data source via web services) to pull in the other data.  Any good hints for doing this?

October 2, 2007 2:59 PM
 

Mako said:

just ran across this post. Tried it. It did not work as expected, so here is my question: When using URLMapping, the InfoPath form receives {0} instead of the actual value of the first parameter. Why? How to fix?

Thanks

February 17, 2008 11:41 PM

Leave a Comment

(required )  
(optional )
(required )  
Add

Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts