Wednesday, September 14, 2011

List Item URL (Edit- Link to Item) using CAML query

The method SP.UI.ModalDialog.showModalDialog can be used for opening list item in model dialog. It requires target URL as input parameter.

<a href="{$hyperLink}" title="{$TaskTitle}" >
<xsl:attribute name="onclick">
SP.UI.ModalDialog.showModalDialog({url:'<xsl:value-of select="$hyperLink"/>' });return false;
</xsl:attribute>
<xsl:value-of select="$TaskTitle"/>
</a>

Below is the complete example. The xml data generated from task list.

E.g

XML

<NewDataSet>
<PMOProject>
<ListId>9C5526E2-205E-491D-865E-2B1FB9634080</ListId>
<WebId>05DEA448-7E27-4104-93CB-27D90A8E9A00</WebId>
<ID>1</ID>
<Title>test123 task</Title>
<Status>Not Started</Status>
<ProjectProperty.Title>test123</ProjectProperty.Title>
<ListProperty.Title>Tasks</ListProperty.Title>
<EncodedAbsUrl>http://sitecoll/</EncodedAbsUrl>
<FileDirRef>1;#sites/PMO/test123/Lists/Tasks</FileDirRef>
</PMOProject>
<PMOProject>
<ListId>E560F3F9-4E80-455D-8840-423B72761007</ListId>
<WebId>50BB0EA1-3004-4DB7-B7CF-30AC2BA0941E</WebId>
<ID>1</ID>
<Title>PMO Task01</Title>
<Status>Not Started</Status>
<ProjectProperty.Title>PMO</ProjectProperty.Title>
<ListProperty.Title>Tasks</ListProperty.Title>
<EncodedAbsUrl>http://sitecoll/</EncodedAbsUrl>
<FileDirRef>1;#sites/PMO/Lists/Tasks</FileDirRef>
</PMOProject>
<PMOProject>
<ListId>E560F3F9-4E80-455D-8840-423B72761007</ListId>
<WebId>50BB0EA1-3004-4DB7-B7CF-30AC2BA0941E</WebId>
<ID>2</ID>
<Title>ssstest321</Title>
<Status>Not Started</Status>
<ProjectProperty.Title>PMO</ProjectProperty.Title>
<ListProperty.Title>Tasks</ListProperty.Title>
<EncodedAbsUrl>http://sitecoll/</EncodedAbsUrl>
<FileDirRef>2;#sites/PMO/Lists/Tasks</FileDirRef>
</PMOProject>
</NewDataSet>

XSLT

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="xml" indent="yes"/>
<xsl:variable name="hyperLink"/>
<xsl:variable name="baseurl"/>
<xsl:variable name="TaskTitle" />
<xsl:key name="proj" match="PMOProject" use="node()[name()='ProjectProperty.Title']" />
<xsl:template match="NewDataSet">
<xsl:for-each select="PMOProject[count(. | key('proj', node()[name()='ProjectProperty.Title'])[1]) = 1]">
<xsl:sort select="node()[name()='ProjectProperty.Title']" />
<b>
<xsl:value-of select="node()[name()='ProjectProperty.Title']" />
</b>
<br />
<xsl:for-each select="key('proj', node()[name()='ProjectProperty.Title'])">
<xsl:sort select="node()[name()='Status']" />
<xsl:variable name="TaskTitle" select="node()[name()='Title']" />
<xsl:variable name="baseurl" select="substring-before(node()[name()='FileDirRef'],'Lists/')"/>
<xsl:value-of select="node()[name()='Status']" /> <xsl:variable name="hyperLink" select="concat(node()[name()='EncodedAbsUrl'],substring-after($baseurl,'#'),'Lists/ProjectPlan/editform.aspx?ID=',node()[name()='ID'])"/>:-
<a href="{$hyperLink}" title="{$TaskTitle}" >
<xsl:attribute name="onclick">
SP.UI.ModalDialog.showModalDialog({url:'<xsl:value-of select="$hyperLink"/>' });return false;
</xsl:attribute>
<xsl:value-of select="$TaskTitle"/>
</a><br />
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

No comments:

Post a Comment