logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Copying Data To/From Primary and Secondary Datasources with ESFormLib
CarpeDatum
#1 Posted : Wednesday, March 30, 2011 8:58:27 AM(UTC)
Rank: Administration

Groups: Registered, Administrators
Joined: 8/17/2010(UTC)
Posts: 6
Location: Denver

A best practice for creating forms that access ESWeb services using InfoPath is to create the connections as secondary data sources instead of primary data sources.

The main reason for doing this is because InfoPath does not complain when new elements or attributes are added to the secondary data source, whereas in a primary data source, an error would occur. This is helpful because the published TM1 views or subsets can be updated slightly in Enterprise Services without requiring your forms to be re-published. Obviously you cannot move dimensions around in the view, or removing dependent attributes, but adding new ones, or removing unused ones will not break your existing forms.

But this creates somewhat of a quandry, because there are some distinct advantages to using a primary data source, such as:

1) Ability for users to add and remove rows from a repeating table
2) Ability to add additional fields and attributes not in the data source
3) Data validation
4) Additional formatting
...and others.

So the question becomes, how do we get the data from the secondary data source into the primary data source?

The answer is ESFormLib. ESFormLib is a library that you can include in your InfoPath code to help you with some common tasks, such as copying data from the primary to secondary data sources and back.

There are two primary functions for handling this:

CopyTableByName
CopyTableByPosition

CopyTableByName will match the element names between the primary and secondary data sources and copy all the rows of data that use the corresponding names. It will even copy any attributes that are named the same between the two data sources. Syntax for using this library function are:

Code:

// Copy from CapEx view to primary data source
es.CopyTableByName("CapExData", "/my:myFields/my:secBody/my:CapExItemTable/my:CapExItemRow");


CopyTableByPosition will match column by column each of the two data sources without regard to the names of the fields. Any attributes on the fields that match the secondary data source will also be copied to the primary data source. Syntax for using this library function are:

Code:

// Copy from CapEx view to primary data source
es.CopyTableByPosition("CapExData", "/my:myFields/my:secBody/my:CapExItemTable/my:CapExItemRow");


Once the user has updated the data in the form, you can copy the data back to the secondary data source and submit it back to ESWeb by simply reversing the direction of the copy function.

Code:

// Copy updated data back to the secondary data source for writing back to TM1
es.CopyTableByName("/my:myFields/my:secBody/my:CapExItemTable/my:CapExItemRow", "CapExData");

// Send the data back to ESWeb
es.SubmitDataSource("CapExData Submit");


So, with three lines of code, you can transfer back and forth between primary and secondary data sources!
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF 1.9.5.5 | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.029 seconds.