I have the unique requirement of needing to get the current user's id (domain\logon) for use within a Content Query Web Part. If no documents are retrieved with the CQWP I need to craft a custom url in the format site/employees/currentuserlogon/. How do i get that information?

The proposed functionality would be as follows:

A user accesses a generic top level page with a Content Query Web Part pulling the most recent form that the user authored. If there is no form that the user authored, than a custom link will appear that allows the user to create a form. The link is user specific, using the logon account as part of the site path.


I haven't done much with the CQWP because I find it falls down as soon as you want to do anything really hard. That said, there's a CAML variable you can use in a DVWP:

<ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>

It probably is available somehow in a CQWP, too.

  • Unfortunately the DVWP isn't working as a rollup with the proper settings. The CQWP works but I need that one piece of information to build the null result link. =( Mar 13 '10 at 15:40
  • Can you add to your post what you're trying to do from a functionality perspective? Mar 13 '10 at 22:27
  • Original post updated, I hope that helps. Thanks! Mar 14 '10 at 0:15
  • 1
    OK, the DVWP should totally be able to do this. When you say form, you mean item(s) in list(s). Are you wanting to look at one list or multiple lists? Either way, it can work with a DVWP. You're going to have far more flexibility with a DVWP. Mar 14 '10 at 17:08
  • DVWP is really the right way to do this, CQWP doesn't allow for this variable out of the box and doesn't seem that you can modify the XSLT to retrieve it. Mar 16 '10 at 10:04

Hopefully someone here knows of a this can be done without needing to write custom code. However I have found before the need to extend the CQWP to send through extra information such as this to the XSLT.

Waldek Mastykarz has some great tutorials for the CQWP and many other things on his blog, of which this is one should help you.


Agreed with Marc on this one the DVWP adds the parameter he mentions above in by default which represents the current userID. Its also really easy to specify a template which will be used when no results are returned. Just click on 'Common Data View Tasks' and select Data View Properties. Under General tick 'Display text if no matching items are found'.

This adds a template to the XSL called 'dvt_1.empty' you can edit this to display your link. All the logic is pre-built for you.

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.