SharePoint Sharpener

Obsessively Sharpening SharePoint

Archive for June 2008

Several ANDs in a CAML Query

with 8 comments

If you are used to writing SQL queries to extract info from databases, using CAML to show data from SharePoint lists can be a bit of a challenge.

The syntax can be slightly cumbersome especially if you’re writing complex queries. Nesting more than a couple of conditions is confusing at first but once you get the hang of it, you’re cruising…

 

Simple AND example

The below example is the SQL equivalent to SELECT * FROM [Table] WHERE Title = ‘foo’:

<Query>
   <Where>
      <Eq>
         <FieldRef Name=’Title’ />
         <Value Type=’Text’>foo</Value>
      </Eq>
   </Where>
</Query>

Now, what happens if you need to do the equivalent of SELECT * FROM [Table] WHERE Title = ‘foo’ AND Name = ‘bar’? Look at this:

<Query>
   <Where>
      <And>
         <Eq>
            <FieldRef Name=’Title’ />
            <Value Type=’Text’>foo</Value>
         </Eq>
         <Eq>
            <FieldRef Name=’Name’ />
            <Value Type=’Text’>bar</Value>
         </Eq>
      </And>
   </Where>
</Query>

So far, so good. The 2 Eq conditions need to be encapsulated by an And.

 

Several ANDs in one query

What if we need three Ands or more in our query? I.e. SELECT * FROM [Table] WHERE Title = ‘foo’ AND Name = ‘bar’ AND Address = ‘foobar’. Check this out:

<Query>
   <Where>
      <And>
         <And>
            <Eq>
               <FieldRef Name=’Title’ />
               <Value Type=’Text’>foo</Value>
            </Eq>
            <Eq>
               <FieldRef Name=’Name’ />
               <Value Type=’Text’>bar</Value>
            </Eq>
         </And>
         <Eq>
            <FieldRef Name=’Address’ />
            <Value Type=’Text’>foobar</Value>
         </Eq>
      </And>
   </Where>
</Query>

The key is to know that the conditions are nested and not just listed in succession.

I’m sure you can guess how a query with 3 ANDs is put together. If not, you should download the excellent CAML Query Builder from U2U:

image

The CAML Query Builder lets you connect to your lists (locally or remotely) and build CAML queries using a point-and-click interface. Highly recommended.

Written by Thomas Sondergaard

June 27, 2008 at 11:57 am

Posted in Development

Tagged with

Script Error in RTF Editor – Work-around

with one comment

If you have worked with a localised version of SharePoint you may have encountered the annoying RTF editor script error.

Basically, the problem renders all instances of the RTF editor unusable, across the MOSS installation due to a common javascript error.

 

Symptoms

Every time a user opens an RTF editor and starts typing, a JavaScript error is fired, making typing almost impossible. This problem seems to be present in only some installations of SharePoint with regional language packs installed.

Here’s a screenshot of a Danish RTF editor with the script error:

image

The screenshot is from an English MOSS server with  the Danish language pack installed.

As annoying as the script error may be, it’s even more aggrevating that the error doesn’t occur on all servers with this exact setup. This means you can’t predict if a server is going to have this problem, purely based on the configuration.

 

Cause

The problem seems to be caused by bad code in one or more of the JavaScript files in the LAYOUTS folder. As you may know, the LAYOUTS folder is common for all sites on the MOSS server, i.e. all folders named _layouts is mapped to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS.

I can only speculate about how this can happen, but perhaps some versions (but not all) of the language packs include faulty JavaScript files. This could explain why this problem doesn’t occur on all MOSS servers with language packs.

 

Solution

Microsoft hasn’t released any fixes to counter this problem and there is no indication as to when or, indeed, if this will happen.

Obviously, my client needed a fix ASAP and this is what I came up with:

First, I installed Fiddler HTTP Debugger to determine which JavaScript files load when the RTF editor is launched.

Fiddler came up with the following list of files:

image

Note that 1030 directory is where the Danish files are located (1033 is English).

I now had a fairly good idea of where the bug was located but I didn’t have the patience to go through all that JavaScript code! Instead I copied the above 7 files from a healthy MOSS server (with Danish language pack) – and lo and behold – everything worked just fine.

My money is on HtmlEditor.js as the most likely culprit but I haven’t checked up on this.

Written by Thomas Sondergaard

June 27, 2008 at 9:06 am

Welcome

leave a comment »

Welcome to my new SharePoint-related blog here at WordPress.com.

As you may know, I also blog at my company’s blog at sharepointblogs.com/peoplenet, however, I’ve had a few problems with the software at sharepointblogs.com so I’ve decided to give WordPress a try.

My aim is to blog once or twice a week, mostly about optimising SharePoint using standard tools, such as Visual Studio and SharePoint Designer – but I also want to share and discuss more obscure ways of getting the most out of the MOSS platform.

Regards,
Thomas Sondergaard

Written by Thomas Sondergaard

June 26, 2008 at 5:41 am

Posted in Off-topic

Tagged with ,