Display an SPFieldUrlValue property from a BCS Model
-
16-10-2019 - |
Question
I have a pretty simple BCS model:
public Guid Id { get; set; }
public SPFieldUrlValue Url { get; set; }
public string Description { get; set; }
public string Owner { get; set; }
public DateTime CreatedOn { get; set; }
The Url property contains both the Title and URL like any SharePoint Hyperlink property. The BCS model has the following Type Descriptor for both the ReadList and ReadItem methods:
<TypeDescriptor Name="Url" TypeName="Microsoft.SharePoint.SPFieldUrlValue">
<Properties>
<Property Name="SPCustomFieldType" Type="System.String">`URL</Property>
</Properties>
</TypeDescriptor>
In the list definition's schema.xml I have the following values for the Fields collection:
<Field Name="BdcIdentity" DisplayName="BDC Identity" Hidden="FALSE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="BdcIdentity" Type="Text" />
<Field Name="Id" DisplayName="Id" Hidden="FALSE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Id" Type="Text" />
<Field Name="Url" DisplayName="Url" Format="Hyperlink" Hidden="FALSE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Url" Type="URL" />
<Field Name="Description" DisplayName="Description" Hidden="FALSE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Description" Type="Text" />
<Field Name="Owner" DisplayName="Owner" Hidden="FALSE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Owner" Type="Text" />
<Field Name="CreatedOn" DisplayName="Created On" Hidden="FALSE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="CreatedOn" Type="DateTime" />
Nothing too fancy. When I open up the default view, however, it does not display the URL properly in the table view - it displays nothing. In the individual item view it does display properly. Any thoughts on how to get an SPFielidUrlValue to render properly on the UI?
Solution
After two and a half months (!!!!) PSS was able to come up with a workaround using a custom XML stylesheet that gets stored in Layouts/Xsl:
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
<xsl:template match="FieldRef[@Name='Url' and @Format='Hyperlink']" mode="URL_body" priority="1">
<xsl:param name="thisNode" select="."/>
<xsl:variable name="url" select="normalize-space(substring-before($thisNode/@*[name()=current()/@Name],','))" />
<xsl:variable name="desc" select="normalize-space(substring-after($thisNode/@*[name()=current()/@Name],','))" />
<xsl:variable name="descfld" select="$thisNode/@Description"/>
<xsl:variable name="urlfld" select="$thisNode/@Url"/>
<!-- URL: <xsl:value-of select="$urlfld" /><br/>
Description: <xsl:value-of select="$descfld" /><br/>
Link: -->
<a href="{$url}" alt="{$desc}">
<xsl:value-of select="$desc"/>
</a>
</xsl:template>
</xsl:stylesheet>
OTHER TIPS
According to the MSDN page BDC Custom Properties:
This property has no effect on methods other than the SpecificFinder.
I am wondering, how can i implement this xsl? Offcourse i can create it, and deploy it into layouts/xsl... But there is no connection between the external list and the xsl file ?