Wednesday, May 30, 2012

Open the Edit Form of External List from BCS Profile Page

Recently I had a business scenario, where the user wanted to use a Business data in not traditional way:

  • To find a particular entity instance with not using of search – the external system contains 20+ millions of entries, the crawl time (full and incremental) will be significant and have to be processed daily
  • To edit an entity instance with no browsing of External List – there is no way to find the particular item in the EL

Finally I designed the following solution:

  • Developed a BCS .net assembly connector in Visual Studio, which connects to Oracle database. It contains a few entities, but for simplicity we will focus on only one – Customer. It has three operations – Finder, Specific Finder and Updater and identifier UNID (string)
  • After deployment on my SPS 2010 I created a profile page in the standard way, through BDC service application’s management page in CA
  • Meanwhile I created a small configurable web part which accepts two parameters (text boxes) Customer_ID and Date (because of the business users), executes a SQL query against the Oracle and returns the UNID of the only record. The web part redirects the user to the profile page, created in the previous step. Actually this small component plays as an “item picker” which opens the item’s profile page!
  • Additionally I created an external list with view and edit forms

So, the biggest question was HOW once landed on the profile page the user can jump directly to the Edit form ??? Where is the problem? The edit form expects a parameter BcsIdentity instead of UNID and there is not a normal way to get it.

  • I added a BCS action (not external list custom action) from BDC service application’s management page in CA. Named it “EDIT” and the URL was the URL of my EditForm.aspx http://myportal/List/MyExternalList/EditForm.aspx?UNID={0}, where UNID is the identifier of my entity
  • The action is visible/accessible from the profile page. Clicking on it the user jumps to EditForm.aspx, but with wrong parameter ?UNID=123456, instead of ?ID=<BcsIdentity> and the form is empty
  • I developed a second web part, which reads the UNID parameter from the query string and encodes it in “a BCS way”

SmileSmileSmile

string unid = qstr["UNID"];
object[] identifiers = { unid };
string identifiersEnc = EntityInstanceIdEncoder.EncodeEntityInstanceId(identifiers);
string newUrl = string.Format("{0}&{1}={2}&source={3}", Page.Request.Url.ToString(),newQstrParamName, identifiersEnc, SPContext.Current.Site.Url);
Page.Response.Redirect(newUrl, true);

Finally the code redirects the browser to the same page (EditForm.aspx) but with newly added parameter ID=”myEncodedIdentifier” and the Edit form work as expected!

Special thanks to Pradeep Kamalakumar, for his significant help!

4 comments:

  1. Would it be possible to get the solution code for the web part? I don't understand where to put the above code...

    ReplyDelete
  2. I found another way of creating the Edit link.

    On your SharePoint 2010 Business Connectivity Services profile page, add a Business Data Item web part and connect it to your External Content Type. By default, this should show a list of properties and values of the Item selected from your Business Data Item Builder web part.

    Now edit the Business Data Item web part and in Data View Properties change the XSL using the XSL Editor to the following:

    <xsl:stylesheet version="1.0" exclude-result-prefixes="xsl"

    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml"
    indent="yes" omit-xml-declaration="yes"/>
    <xsl:template match="/">
    <a
    href="/sitepath/Lists/listname/EditForm.aspx?ID={/dsQueryResponse/NewDataSet/Row/@BdcIdentity}">Edit
    Asset</a>
    </xsl:template>
    </xsl:stylesheet>
    where you need to change “/sitepath/Lists/listname/EditForm.aspx” to the path of your edit form;
    and OK.

    This should give you a link named Edit Asset which goes to the Edit form of your List, opening the correct item for editing, selected by the BDC Identity value in the ID URL parameter.

    ReplyDelete
  3. Some truly superb blog posts on this web site ,thank you for contribution.
    sharepoint online training

    ReplyDelete