Click here to Skip to main content
6,822,123 members and growing! (20,133 online)
Email Password   helpLost your password?
Enterprise Systems » SharePoint Server » General     Intermediate License: The Code Project Open License (CPOL)

SharePoint CAML Query builder dialog for your Web Parts

By Sike Mullivan

SharePoint CAML Query builder dialog for your Web Parts
C#, Javascript, .NET, ASP.NET, Dev
Revision:9 (See All)
Posted:21 Feb 2009
Updated:24 Mar 2009
Views:25,544
Bookmarked:22 times
Unedited contribution
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
8 votes for this article.
Popularity: 4.40 Rating: 4.88 out of 5

1

2

3
1 vote, 12.5%
4
7 votes, 87.5%
5
QueryBuilder.png

Introduction

I've been writing web parts for quite some time now and I came to realize that I have a lot of web parts that use CAML queries to pull information from lists. Because of this, our users were unable to actually configure these web parts themselves. Instead, they relied upon the administration group to build their queries for them. It was ok for a little while but as the popularity for the webparts grew within the company, we grew tired of having to build these queries for them. Since many of my web parts use CAML queries I figured I'd need to find a way to spread this functionality across all of them. That's why I decided to have this feature work just like the List selector dialog that you see in the Content Query web part. I'll explain more below.

Background

So I'll first go about how I figured out how to use SharePoints framework for creating a dialog page in SharePoint.

First, drop a Content Query web part into a web part zone on one of your pages. Then lets go ahead and modify its properties. Now click the "Show items from the following list" radio button and then hit "Browse".

PickerTreeDialog.png

As you can see it pops up the PickerTreeView.aspx page with a bunch of query strings appended to the end. If you select a list and click ok then values will be returned to the text box in your original window. So lets find out how this happens.

Here's a little trick I like to do. Mouse over the Browse button and you'll get a tool tip "Open a new window to select a list".

PickerTreeBrowseButton.png

Right click the web page and go to "View Source". Hit ctrl+F and then type in the tool tips text. Click "Find" and boom we are at our buttons html.

PickerTreeOnclick.png

OK, now you'll be able to see when the users clicks the button it fires the javascript method mso_launchListSmtPicker(). So lets hit ctrl+F and see if we can find this method in the source of this page. And yes, it's in this page towards the top.

LaunchPickerTreeDialog.png

So after some analysis of this method we find that a callback (the callback sets our controls with the returned values from the dialog) method is created and is passed to LaunchPickerTreeDialog which must be the method that launches the PickertTreeDialog window. So lets try and find it. First we can ctrl+F and see if it's in this page but I'll save you the time and tell you it's not there. So what will we do? We'll just launch VS and use the script debugger. So if your in IE 7 click Alt and you'll see the classic menu show up. Then go to View -> Script Debugger -> Open. Then start up a new instance of VS. The pages html will load up along with all the javascript files that are referenced. If we look at the list of javascript pages referenced we'll see the PickerTreeDialog.js which we can safely assume the LaunchPickerTreeDialog method is in that file.

VSPickerTreeDialog.png

 // _lcid="1033" _version="12.0.6211"
// _localBinding
// Version: "12.0.6211"
// Copyright (c) Microsoft Corporation.  All rights reserved.
var PickerTreeDlgUrl="/_layouts/PickerTreeView.aspx";
var PickerTreeDlgDimension="resizable:yes;status:no;location:no;menubar:no;help:no";
var L_WarningFailedOperation_TEXT="Do you wish to continue?";
var L_NullSelectionText_TEXT="Please select a target or click cancel";
var MAX_SOURCEID_LENGTH=1024;
var IdSeparator=",";

function LaunchPickerTreeDialog(title, text, filter, anchor, siteUrl, select, featureId, errorString, iconUrl, sourceSmtObjectId, callback)
{
   var sourceInfo=false;
   var sources=null;
   if(sourceSmtObjectId !=null && sourceSmtObjectId.length > MAX_SOURCEID_LENGTH)
   {
    sources=sourceSmtObjectId.split(IdSeparator);
    if(sources.length > 1)
    {
     sourceInfo=true;
    }
   }
   var sourceObjectIdAppend=(sourceInfo)? sources[0] : sourceSmtObjectId;
   var dialogUrl=TrimLastSlash(siteUrl)+PickerTreeDlgUrl+"?title="+title+       "&text="+text+       "&filter="+filter+       "&root="+anchor+      
             "&selection="+select+       "&featureId="+featureId+       "&errorString="+errorString+       "&iconUrl="+iconUrl+       
             "&sourceId="+sourceObjectIdAppend;
  commonShowModalDialog(dialogUrl, PickerTreeDlgDimension, callback, null);
}

function HandleOkReturnValues(strDlgReturnValue, strDlgReturnErr)
{
 if (strDlgReturnValue[0].indexOf("Error:") >=0)
 {
  alert( strDlgReturnValue[0].slice(7));
 }
 else
 {
  if(strDlgReturnErr.indexOf("Error:") >=0)
  {
   var promptUser=strDlgReturnErr.slice(7)+"."+L_WarningFailedOperation_TEXT;
   if(confirm(promptUser)==0)
    return false;
  }
  setModalDialogReturnValue(window,strDlgReturnValue);
  window.top.close();
 }
 return false;
}

So what does this method do? All it really does is prepare some information to be sent into the commonShowModalDialog method. The commonShowModalDialog is a core.js method that contains all the logic for showing dialogs. All you have to do is give it a URL, some Parameters such as the info in PickerTreeDlgDimension and a callback method that will be invoked after the user clicks OK or Cancel from the dialog page. Pretty sweet eh?

So now that we know how to load up the page. Let's figure out how information gets sent back from the dialog to our original window. Let's find the PickerTreeView.aspx page in the layouts directory (C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\TEMPLATE\LAYOUTS) and open it up. So after analyzing the page we can cut out alot of asp and reuse it as a base template for any future dialogs. The main thing to get from this is that dialog pages use the Dialog.Master master page instead of Application.Master. This master page provides the consistent look and feel of all dialog pages.

<%@ Page Language="C#" AutoEventWireup="true"  MasterPageFile="~/_layouts/dialog.master" CodeBehind="MYCLASS.aspx.cs" 
         Inherits="Mullivan.SharePoint.Pages.MYCLASS,Mullivan.SharePoint.Pages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c37a514ec27d3057" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<asp:Content ID="Content1" contentplaceholderid="PlaceHolderDialogHeaderPageTitle" runat="server">
  <asp:Literal runat="server" ID="dialogTitle" />
</asp:Content>
<asp:Content ID="Content2" contentplaceholderid="PlaceHolderAdditionalPageHead" runat="server">
 <SharePoint:ScriptLink ID="ScriptLink2" language="javascript" name="core.js" runat="server" />
 <script type="text/javascript" language="javascript">
     function HandleOkClicked() {
             var strDlgReturnValue = new Array(3);
           strDlgReturnValue[0] = "value5";
             strDlgReturnValue[1] = "Value4";
             strDlgReturnValue[2] = "Value3";
             var strDlgReturnErr = "";//Set this if an error occurs
             if(strDlgReturnValue[0] == null || strDlgReturnValue[0].length <= 0)
             {
                 alert(L_NullSelectionText_TEXT);
             }
             else
             {
               return HandleOkReturnValues(strDlgReturnValue, strDlgReturnErr);         
             }
 </script>
 <SharePoint:FormDigest ID="FormDigest1" runat="server"/>
</asp:Content>
<asp:Content ID="Content3" contentplaceholderid="PlaceHolderDialogImage" runat="server">
 <asp:Image ID="imgIcon" width="32" height="32" runat="server" />
</asp:Content>
<asp:Content ID="Content4" contentplaceholderid="PlaceHolderDialogDescription" runat="server">
 <asp:Literal runat="server" ID="dialogDescription" />
</asp:Content>
<asp:Content ID="Content5" contentplaceholderid="PlaceHolderHelpLink" runat="server">
</asp:Content>
<asp:Content ID="Content6" contentplaceholderid="PlaceHolderDialogBodyMainSection" runat="server">
<!-- This is the main body of our page. So any controls you want to be in the dial
go here -->
</asp:Content>

Take a look above and you'll see the method HandleOkReturnValues. This is the method that we seen above in the PickerTreeView.js that calls setModalDialogReturnValue. This is a core.js method that invokes the callback method provided by mso_LaunchSmtListPicker. HandleOkClicked is just a simple method that illustrates how values are passed back. To register it to be called by the OK button of the master page we need to add the following code behind to our new dialog page.

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            ((DialogMaster)base.Master).OkButton.Click += new EventHandler(OkButton_Click);
        }

If this doesn't make complete sense to you yet, hopefully when you use the query builder and look at the code it will help clear things up.

Installation

GAC the following dlls (Located in the Build Folder)

Mullivan.Shared.dll
Mullivan.SharePoint.dll
Mullivan.SharePoint.Pages.dll
Mullivan.SharePoint.Reminders.dll
Mullivan.SharePoint.WebParts.dll

Navigate to C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\TEMPLATE\LAYOUTS

Copy Build\Layouts\QueryBuilder.aspx to this dir
Copy Build\Layouts\FieldValueDialog.aspx to this dir

Navigate to C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\1033

Copy Build\Layouts\1033\QueryBuilder.js to this dir
Copy Build\Layouts\1033\MullivanUtility.js to this dir
Copy Build\Layouts\1033\FieldValueDialog.js to this dir

Register Webparts

Register Mullivan.SharePoint.WebParts.dll in the SharePoint Web Config.

Go to C:\inetpub\wwwroot\wss\VirtualDirectories\<Port Number>\web.config. Add the following in between the SafeControls node:

<SafeControl 
Assembly="Mullivan.SharePoint.WebParts, Version=1.0.0.0, 
Culture=neutral, PublicKeyToken=c37a514ec27d3057"
Namespace="Mullivan.SharePoint.WebParts" TypeName="*" Safe="True" />

Go to Site Settings -> Webparts -> click New on the menu.

Scroll to the bottom and check Mullivan.SharePoint.WebParts.ListQueryWebPart and Mullivan.SharePoint.WebParts.ListQueryResultsWebPart, and then scroll back to the top and click Populate Gallery.

Restart

Go to Start -> Run and type iisreset and click ok

Using the Query Builder

Lets take a look at the ListQueryWebPart and ListQueryResultsWebPart that I had you install. Go ahead and drop both into a web part zone and click connect the two web parts up. Then click "Modify SharePoint Web Part" on the ListQueryWebPart.

WebPartProperties.png

Go ahead and pick a list you want to query by hitting "Browse" and then click the "Build" button for either view or query. You'll see the QueryBuilder window come up. OK.. go ahead and have fun. If you want to test out a query then make sure you drop a ListQueryResultsWebPart on the page and connect the two web parts up.

Clicking the "Build" button for view

ViewDialog.png

In this dialog you'll choose all the fields that you want to come back in your list query.

Clicking the "Build" button for Query

QueryDialog.png

IsUserInput.png

Here is the dialog you will use to build your query. The User Input checkbox is a feature that the ListQueryWebPart uses to work like a templated search. Basically, all the conditions that you want to define values for in the ListQueryWebPart need to be set as User Input. Let me show you a screen shot of what the ListQueryWebPart looks like after the above CAML query is saved.

ListQueryWebPart.png

If you define a condition as User Input then the ListQueryWebPart will render an edit control to the page and insert the value into the CAML query when you click "Search". The ListQueryWebPart requires at least one User Input condition to work.

If your web part uses the User Input feature of the Query Builder you'll need to parse out the <UserInput /> tags that are used as placeholders for the <Value /> tag that will need to be placed in there. FYI, here is the CAML query that was passed back to the ListQueryWebPart by the Query Builder.

  <Where>
    <And>
      <And>
        <Contains>
          <FieldRef Name='MultiSelect'  />
          <UserInput />
        </Contains>
        <Contains>
          <FieldRef Name='Column2'  />
          <UserInput />
        </Contains>
      </And>
      <And>
        <Geq>
          <FieldRef Name='Created'  />
          <UserInput />
        </Geq>
        <Eq>
          <FieldRef Name='MultiLookup' LookupId='True' />
          <UserInput />
        </Eq>
      </And>
    </And>
  </Where>
  <OrderBy>
    <FieldRef Name='Modified' Ascending='True' />
  </OrderBy>

If you choose not to allow the User Input then it forces you to put a value in during the creation of the CAML Query.

If your not sure what kind of data goes into your column then just click the edit dialog button. This will help you find lookups, users, choices, and etc. It's really handy.

EditDialog.png

Using the code

So lets take a look on how to use the Query Builder dialog. Let's take a look at some source code. Open up the ListQueryEdit.cs file in the Mullivan.SharePoint.WebParts project. This is the editor control that is used by the ListQueryWebPart. It registers our javascript files and then loads controls that have associated buttons that pop up the dialog windows. These windows will then return values back and set the textboxs with them.

using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls;
using System.Web.UI;
using Microsoft.SharePoint;
namespace Mullivan.SharePoint.WebParts
{
    public class ListQueryEditor : EditorPart
    {
        private TextBox _tboxList = null;
        private TextBox _tboxViewFields = null;
        private TextBox _tboxQuery = null;
        private TextBox _tboxPageSize = null;
        private RangeValidator _rvPageSize = null;
        public ListQueryEditor(string webPartId)
        {
            this.ID = webPartId + "_ListQueryEditor";
        }
        protected override void OnInit(EventArgs e)
        {
            _tboxList = new TextBox();
            _tboxViewFields = new TextBox();
            _tboxQuery = new TextBox();
            _tboxPageSize = new TextBox();
            _rvPageSize = new RangeValidator();
            _tboxList.ID = "tboxList";
            _tboxViewFields.ID = "tboxViewFields";
            _tboxQuery.ID = "tboxQuery";
            _tboxPageSize.ID = "tboxPageSize";
            _rvPageSize.ID = "rvPageSize";
            _rvPageSize.ControlToValidate = "tboxPageSize";
            _rvPageSize.ErrorMessage = "Page size must be an integer between 1 and 1000.";
            _rvPageSize.MaximumValue = "1000";
            _rvPageSize.MinimumValue = "1";
            _rvPageSize.Type = ValidationDataType.Integer;
            
            base.OnInit(e);
        }
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            #region "HTML"
            Literal litBeginHtml = new Literal();
            litBeginHtml.Text = @"
<br />
<div>
<table cellspacing=""0"" cellpadding=""0"" border=""0"" style=""width:0px; width:100%;border-collapse:collapse;"">
 <tr>
  <td>
            <div class=""UserSectionTitle"">
                <a id=""{0}_MVQueryCategory_IMAGEANCHOR"" TabIndex=""0"" onkeydown='MSOMenu_KeyboardClick(this, 13, 32);' 
                style='cursor:hand' 
                onclick=""javascript:MSOTlPn_ToggleDisplay('{0}_MVQueryCategory', '{0}_MVQueryCategory_IMAGE', '{0}_MVQueryCategory_ANCHOR', 'Expand category: Query', 'Collapse category: Query','{0}_MVQueryCategory_IMAGEANCHOR');"" 
                title=""Collapse category: Query"" >
                     <img id=""{0}_MVQueryCategory_IMAGE"" alt=""Collapse category: Query"" border=""0"" src=""/_layouts/images/TPMin2.gif"" /> 
                </a>
                <a TabIndex=""-1"" 
                    onkeydown='MSOMenu_KeyboardClick(this, 13, 32);' 
                    id=""{0}_MVQueryCategory_ANCHOR"" 
                    style='cursor:hand' 
                    onclick=""javascript:MSOTlPn_ToggleDisplay('{0}_MVQueryCategory', '{0}_MVQueryCategory_IMAGE', '{0}_MVQueryCategory_ANCHOR', 'Expand category: Query', 'Collapse category: Query','{0}_MVQueryCategory_IMAGEANCHOR');"" 
                    title=""Collapse category: Query"" > Query
                </a>
            </div>
        </td>
    </tr>
</table>
<div id=""{0}_MVQueryCategory"">
    <table cellspacing=""0"" border=""0"" style=""border-width:0px;width:100%;border-collapse:collapse;"">";
            Literal litEndHtml = new Literal();
            litEndHtml.Text = @"
    </table>
</div>";
            #endregion "HTML"
            this.Controls.Add(litBeginHtml);
            string listClientId = this.ClientID + "_tboxList";
            string viewClientId = this.ClientID + "_tboxViewFields";
            string queryClientId = this.ClientID + "_tboxQuery";
            string serverUrl = SPContext.Current.Web.ServerRelativeUrl.Replace("/", "file://u002f/">\\u002f");
            string editListJS = string.Format("LQWP_LaunchListPicker('{0}','{1}')", listClientId, serverUrl);
            string editViewJS = string.Format("LQWP_LaunchViewBuilder('{0}','{1}','{2}')", listClientId, viewClientId, serverUrl);
            string editQueryJS = string.Format("LQWP_LaunchQueryBuilder('{0}','{1}','{2}')", listClientId, queryClientId, serverUrl);
            AppendEditControl("List"
                , "Value that represents the list that is set to be queried."
                ,_tboxList
                ,this.Controls
                , "Browse..."
                , editListJS
                , null);
            AppendEditControl("View"
                , "The fields that you would like to display in the results."
                , _tboxViewFields
                , this.Controls
                , "Build..."
                , editViewJS
                , null);
            AppendEditControl("Query"
                , "The CAML query that will be used to search the list."
                , _tboxQuery
                , this.Controls
                , "Build..."
                , editQueryJS
                ,null);
            AppendEditControl("Page Size"
                , "The amount of items that should be displayed per page."
                , _tboxPageSize
                , this.Controls
                , null
                , null
                ,_rvPageSize);
            this.Controls.Add(litEndHtml);
        }
        protected override void OnPreRender(EventArgs e)
        {
            ClientScriptManager csm = this.Page.ClientScript;
            Type lnType = this.GetType();
            //Register our Javascript file
            if (!csm.IsClientScriptIncludeRegistered(@"Mullivan.SharePoint.WebParts.JS.Utility.js"))
            {
                string url = csm.GetWebResourceUrl(lnType, @"Mullivan.SharePoint.WebParts.JS.Utility.js");
                csm.RegisterClientScriptInclude(lnType, "Mullivan.SharePoint.WebParts.JS.Utility.js", ResolveClientUrl(url));
            }
            if (!csm.IsClientScriptIncludeRegistered(@"Mullivan.SharePoint.WebParts.JS.ListQuery.js"))
            {
                string url = csm.GetWebResourceUrl(lnType, @"Mullivan.SharePoint.WebParts.JS.ListQuery.js");
                csm.RegisterClientScriptInclude(lnType, "Mullivan.SharePoint.WebParts.JS.ListQuery.js", ResolveClientUrl(url));
            }
            if (!csm.IsClientScriptIncludeRegistered(@"PickerTreeDialog"))
            {
                string url = @"/_layouts/1033/PickerTreeDialog.js";
                csm.RegisterClientScriptInclude(lnType, "PickerTreeDialog", url);
            }
            if (!csm.IsClientScriptIncludeRegistered(@"QueryBuilderDialog"))
            {
                string url = @"/_layouts/1033/QueryBuilder.js";
                csm.RegisterClientScriptInclude(lnType, "QueryBuilderDialog", url);
            }
            base.OnPreRender(e);
        }
        private void AppendEditControl(string displayName, string description
            , WebControl control, ControlCollection controlCollection
            , string editText, string editJS, Control validationControl)
        {
            Literal litBeginHtml = new Literal();
            Literal litEndHtml = new Literal();
            controlCollection.Add(litBeginHtml);
            controlCollection.Add(control);
            if (validationControl != null)
                controlCollection.Add(validationControl);
            controlCollection.Add(litEndHtml);
            litBeginHtml.Text = string.Format(@"
  <tr>
   <td>
       <div class=""UserSectionHead"">
           <LABEL FOR=""{0}"" 
                  TITLE=""{2}"">{1}
           </LABEL>
       </div>
       <div class=""UserSectionBody"">
           <div class=""UserControlGroup"">
               <table cellpadding=""0"" cellspacing=""0"" border=""0"">
                       <tr style=""text-align:left"">
                           <td>", control.ClientID, displayName, description);
            litEndHtml.Text = @"
                                    </td>
                       </tr>
                       <tr style=""text-align:right;{0}"">
                           <td><input type=""button""  
                                   value=""{1}"" 
                                   title=""Click to edit."" 
                                   tabindex=""0"" 
                                   class=""ms-PropGridBuilderButton"" 
                                   style=""display:inline;cursor:pointer;width:55px;text-align:center""
                                   onclick=""javascript:{2}"" />
                           </td>
                       </tr>
                   </table>
           </div>
       </div>
       <div style='width:100%' class='UserDottedLine'>
       </div>
      </td>
     </tr>";
            string display = "";
            if (string.IsNullOrEmpty(editText))
            {
                editText = string.Empty;
                editJS = string.Empty;
                display = "display:none";
            }
            litEndHtml.Text = string.Format(litEndHtml.Text, display, editText, editJS);
            
            control.CssClass = "UserInput";
            control.Style[HtmlTextWriterStyle.Width] = "176px";
        }
        public override bool ApplyChanges()
        {
            EnsureChildControls();
            ListQueryWebPart lqwp = this.WebPartToEdit as ListQueryWebPart;
            if (lqwp == null)
                return false;
            lqwp.Query = _tboxQuery.Text;
            lqwp.ListUrl = _tboxList.Text;
            lqwp.ViewFields = _tboxViewFields.Text;
            lqwp.PageSize = uint.Parse(_tboxPageSize.Text);
            return true;
        }
        public override void SyncChanges()
        {
            EnsureChildControls();
            ListQueryWebPart lqwp = this.WebPartToEdit as ListQueryWebPart;
            if (lqwp == null)
                return;
            _tboxQuery.Text = lqwp.Query;
            _tboxList.Text = lqwp.ListUrl;
            _tboxViewFields.Text = lqwp.ViewFields;
            _tboxPageSize.Text = lqwp.PageSize.ToString();
        }
    }
}
       

Above you'll see that we registered the Mullivan.SharePoint.WebParts.JS.ListQuery.js, so lets take a look at it. This contains our javascript methods for using the PickertTreeView dialog and the query builder dialog.

var lastSelectedListId = null;
function LQWP_LaunchListPicker(clientId, serverUrl) {
    var callback = function(results) {
        LQWP_SetList(clientId, results);
    };
    LaunchPickerTreeDialog('CbqPickerSelectListTitle', 'CbqPickerSelectListText', 'listsOnly', '', serverUrl, lastSelectedListId, '', '', '/_layouts/images/smt_icon.gif', '', callback);
}
function LQWP_SetList(clientId, results) {
    var listTextBox = document.getElementById(clientId);
    if (results == null
        || results[1] == null
        || results[2] == null) return;
    if (results[2] == "") {
        alert("You must select a list!.");
        return;
    }
    lastSelectedListId = results[0];
    var listUrl = '';
    if (listUrl.substring(listUrl.length - 1) != '/')
        listUrl = listUrl + '/';
    if (results[1].charAt(0) == '/')
        results[1] = results[1].substring(1);
    listUrl = listUrl + results[1];
    if (listUrl.substring(listUrl.length - 1) != '/')
        listUrl = listUrl + '/';
    if (results[2].charAt(0) == '/')
        results[2] = results[2].substring(1);
    listUrl = listUrl + results[2];
    listTextBox.value = listUrl;
}
function LQWP_LaunchQueryBuilder(listClientId, queryClientId, serverUrl) {
    var queryTextBox = document.getElementById(queryClientId);
    var listTextBox = document.getElementById(listClientId);
    if (listTextBox.value.replace(/^\s+|\s+$/g, "") == "") {
        alert("A list must be selected before building a query.");
        return;
    }
    var callback = function(results) {
    LQWP_SetQuery(queryClientId, results);
    };
    var query = queryTextBox.value;
    query = Mullivan.Utilities.UrlEncode(query);
    QB_LaunchQueryBuilderDialog(serverUrl, listTextBox.value, null, query, false, true, true, callback);
}
function LQWP_SetQuery(clientId, results) {
    var queryTextBox = document.getElementById(clientId);
    if (results == null || results.length < 2)
        return;
    //Index 1 contains the query and 0 is for the view if it is being used.
    queryTextBox.value = results[1];
}
function LQWP_LaunchViewBuilder(listClientId, viewClientId, serverUrl) {
    var viewTextBox = document.getElementById(viewClientId);
    var listTextBox = document.getElementById(listClientId);
    if (listTextBox.value.replace(/^\s+|\s+$/g, "") == "") {
        alert("A list must be selected before building a query.");
        return;
    }
    var callback = function(results) {
    LQWP_SetView(viewClientId, results);
    };
    var view = viewTextBox.value;
    view = Mullivan.Utilities.UrlEncode(view);
    QB_LaunchQueryBuilderDialog(serverUrl, listTextBox.value, view, null, true, false, false, callback);
}
function LQWP_SetView(clientId, results) {
    var viewTextBox = document.getElementById(clientId);
    if (results == null || results.length < 2)
        return;
    //Index 1 contains the query and 0 is for the view if it is being used.
    viewTextBox.value = results[0];
}
      

And Voila

Wow... thats a long article and I'm really tired. Please give feedback.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Sike Mullivan


Member
I am a Sr SharePoint Developer in Saint Louis, MO. I've been developing professionally for about four years now. For three years I worked for a Document Imaging company that developed applications for Scanning, Indexing, Migrating, and Searching SharePoint (MOSS, WSS). I'm now working on a team for a Cable company that customizes their internal and external SharePoint implementations.
Occupation: Software Developer (Senior)
Location: United States United States

Other popular SharePoint Server articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 52 (Total in Forum: 52) (Refresh)FirstPrevNext
Questionvalue does not fall within the expected range Pinmemberhongzeniu20:39 20 Dec '09  
GeneralSike Mullivan Please help on this simple requirement. PinmemberMember 4656815:36 25 Oct '09  
QuestionGreat article - 1 question PinmemberArkitec17:43 20 Sep '09  
AnswerRe: Great article - 1 question PinmemberSike Mullivan4:49 21 Sep '09  
AnswerRe: Great article - 1 question PinmemberArkitec16:22 21 Sep '09  
GeneralInvalid query??!! Pinmembersuissa2:13 11 Sep '09  
GeneralRe: Invalid query??!! Pinmembersuissa2:14 11 Sep '09  
Generaledit dialog Pinmembersuissa4:05 19 Aug '09  
GeneralRe: edit dialog PinmemberSike Mullivan5:32 19 Aug '09  
GeneralRe: edit dialog Pinmembersuissa5:56 19 Aug '09  
GeneralContent Query web part Pinmembertopgun12321:36 13 Jul '09  
GeneralNested CAML Queries Pinmembers.c.vinod20:05 12 Jul '09  
Generalwowoooo.. gr8 post... one question though Pinmemberumang5510:01 1 May '09  
GeneralRe: wowoooo.. gr8 post... one question though PinmemberSike Mullivan10:37 1 May '09  
GeneralRe: wowoooo.. gr8 post... one question though Pinmemberumang5511:11 1 May '09  
GeneralMe again - No Data Pinmemberchoggatt13:06 30 Apr '09  
GeneralRe: Me again - No Data PinmemberSike Mullivan4:37 1 May '09  
GeneralRe: Me again - No Data Pinmemberchoggatt4:49 1 May '09  
GeneralRe: Me again - No Data PinmemberSike Mullivan5:02 1 May '09  
GeneralRe: Me again - No Data Pinmemberchoggatt5:17 1 May '09  
GeneralRe: Me again - No Data PinmemberSike Mullivan5:41 1 May '09  
GeneralRe: Me again - No Data Pinmemberchoggatt5:47 1 May '09  
GeneralRe: Me again - No Data PinmemberSike Mullivan10:38 1 May '09  
GeneralRe: Me again - No Data Pinmemberchoggatt10:48 1 May '09  
GeneralRe: Me again - No Data PinmemberSike Mullivan11:10 1 May '09  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.

PermaLink | Privacy | Terms of Use
Last Updated: 24 Mar 2009
Editor: Sean Ewington
Copyright 2009 by Sike Mullivan
Everything else Copyright © CodeProject, 1999-2010
Web17 | Advertise on the Code Project