1

In a view of a custom list, I want to add a Script call to a link which opens a custom application page inside a model dialog. The JS function needs the current Item ID as a parameter, so I create the link inside the view like this:

<a href="javascript:openDialog({@ID})">

but {@ID} results to a GUID, but I just need the content of the ID column of the list item. How do I get that?

Thanks!

  • Are you sure? afaik, @ID is the ID indeed – MdMazzotti Mar 18 '14 at 11:01
2

How to pass list item Id in Xsl for List View:

<a>
    <xsl:attribute name="href">javascript:openDialog(<xsl:value-of select="$thisNode/@ID"/>);</xsl:attribute>
    <xsl:value-of select="$thisNode/@Title"/>
</a>

Example of customizing field in SharePoint 2010

The following template

  <xsl:template name="FieldRef_printTableCell_EcbAllowed.Details" match="FieldRef[@Name='Details']" mode="printTableCellEcbAllowed" ddwrt:dvt_mode="body" >
    <xsl:param name="thisNode" select="."/>
    <td>
      <a>
        <xsl:attribute name="href">javascript:openDialog(<xsl:value-of select="$thisNode/@ID"/>);</xsl:attribute>
        <xsl:value-of select="$thisNode/@Title"/>
      </a>
    </td>
  </xsl:template>

renders field named Details as:

<td class="ms-vb-lastCell"><a href="javascript:openDialog([Item Id]);">[Title]</a></td>

References

<xsl:attribute> Element

| improve this answer | |
  • I tried <img src="somepath" OnClick= "openTTDialog('{$this/@ID}')" /> which results to a GUID too. How does that translate to that strange xsl:attribute syntax you use? – elsni Mar 18 '14 at 13:54
  • The answer has been updated to make it more clear – Vadim Gremyachev Mar 18 '14 at 16:59
0

If you use the internal name "ows_ID" (instead of "ID") does that work?

I created a test custom list and examined the schema of the list using powershell (see image).

After getting a reference to the list in $list, I was able to get at the ID (which was "1" and not a GUID) like this:

$items = $list.items
$item  = $item[0]
$item["ows_ID"]

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.