This project has moved and is read-only. For the latest updates, please go here.

DataSheet view CAML change

May 25, 2014 at 5:45 PM
Hi All,

I would like to set the CAML of datasheet view in Moss2010 with jQuery.
Since sharepoint designer is disabled, this is the only option to set the control correctly.

The only thing to set is the following in the code:
    <Eq><FieldRef Name="AssignedTo"/><Value Type="Integer"><UserID Type="Integer"/></Value></Eq>
    <Membership Type="CurrentUserGroups"><FieldRef Name="AssignedTo"/></Membership>
Please help if it is doable, thanks!
May 27, 2014 at 12:31 PM
If you're trying to modify the datasheet view in your SharePoint page at runtime, I'm pretty sure SPServices isn't going to help. It does not have hooks into the datasheet view. I'm not aware of anything that can modify the datasheet view.

May 27, 2014 at 2:06 PM
Agreed, Geoff. Datasheet view is an ActiveX control, not markup.

May 27, 2014 at 6:19 PM
Edited May 27, 2014 at 6:26 PM
Thanks, Geoff, Marc,

I understand that this is an ActiveX. I am just wondering, how is it then possible to modify CAML in SPD, which I think is passed then through to the ActiveX control?
CAML is a sharepoint term, which is included in the <ListViewXml></ListViewXml> tag.

Might there be a $(document). ... (SPServices?) function to replace "CAML code" within the ListViewXml from A to B (as above) before passing the code to the ActiveX control?

I am not trying to make any change to the ActiveX, I only try to change the code passed through to it, since SPD is disabled on MOSS 2010 farm.

Thanks: Blaze
May 27, 2014 at 6:35 PM
I sense you may not be talking about the Datasheet view. Can you explain what you are trying to do? Maybe post the code you have so far?

May 27, 2014 at 8:18 PM
Edited May 27, 2014 at 8:33 PM
I am not an xpert, but try to explain then :

1) I create a "Custom list in datasheet view" web part in a Sharepoint 2010 site:

2) then I constrain this custom web part to active user workgroup:
If I have SPD, I can do this easily, locating the saved "Custom list in datasheet view" web part's aspx page in SPD:

And changing the CAML section within the <ListViewXml></ListViewXml> tag on the "Custom list in datasheet view" web part's aspx page (refer as CAML code's place) manually, and saving it:

The last two screenshots are from SPD 2007, however the same should be done on SP 2010 page, on the fly, since SPD 2010 is disabled.

Is it possible to update the "CAML code's place" like explained above with help of SPServices jQuery, before the page loads / passes the parameters to the ActiveX ?
Like using a jQuery code as [replace "old <where>... text" within the "CAML code's place" with "new <where>... text"] before load and pass to ActiveX ?
May 27, 2014 at 8:51 PM
The method you described above makes a permanent change to the view design (and will affect all users that access the view in the future). Is that your intent? If so, you can use the "UpdateView" method of SPServices to make the change.
Marked as answer by eli5spdesigner on 5/29/2014 at 2:08 PM
May 28, 2014 at 12:26 AM
Out-of-the-box I am only able to constrain column which shows who needs to deal with the given line to [Me].
However, the filter column contains user groups as well, since more than one people should have access to the given list item.

Out-of-the-box the CAML code will look like:
    <Eq><FieldRef Name="AssignedTo"/><Value Type="Integer"><UserID Type="Integer"/></Value></Eq>
This should be replaced with the code above. Temporary and permanent replacement is fine as well, I am just wondering how to do that out-of-the box?

Would it be something like:
function UpdateView(url,list,view)
    var viewname = "";
    $().SPServices({ operation: "GetViewCollection" ... is this standard?})

    var query = CAML as above
    $().SPServices({ operation: "UpdateView",
        webURL: url,
        async: false,
        listName: list, 
        viewName: viewname,
        query: query,
        completefunc: function (xData, Status) ... do I miss anything?
Is this safe? Will this not blow off my sharepoint site?
Marked as answer by eli5spdesigner on 5/29/2014 at 2:09 PM
May 28, 2014 at 1:40 AM
Edited May 28, 2014 at 6:27 AM
This rocks, works like charm, its beautiful, thanks Geoff, Mark! Really useful!!! :-)

Only thing that if I run UpdateView, the list and view is somehow mixed. Could this be as the UpdateView method only updates the CAML of the list, not the view?

Thanks again, this saves a lot of time: Blaze
May 28, 2014 at 6:12 PM
Edited May 29, 2014 at 12:50 PM
I'm not sure what you mean by the list and view being mixed. When you run the "UpdateView" method, it has the same effect as if you selected "Modify View"on your List toolbar and manually updated/saved the view.
May 28, 2014 at 7:15 PM
After running UpdateView(url,list,view), the list itself (allitemsg.aspx above) will be updated, the view (Test1.aspx above) will not change.
So if I click on the allitem view, it will be a constrained view, if I click on the custom view, it does not have the filter.
May 29, 2014 at 1:02 PM
I'm not sure what you're using to identify the view you want to modify but according to the Microsoft documentation , you have to use the view's GUID and not the display name. If you get the views collection from the list, the "Name" attribute of each view is actually the view's GUID while the "DisplayName" attribute is the display name. In the SPServices documentation example, the code enumerates the views collection to find a particular display name (DisplayName) in order to get the GUID (Name) and stores it in the variable "viewname". It then uses that variable (which is actually the view's GUID) in the UpdateView method.
May 29, 2014 at 2:12 PM
Why wouldn't you just go into the settings for the view in the UI and add the filtering you want? I may be missing it, but I'm not sure you need any code here at all.

May 29, 2014 at 10:00 PM
In the UI it is only possible to filter to [Me], not to the current user membership.
So if I want to filter the list to a group which the current user is member of, I need some code.
/Groups are need as I expect more than one person editing the same list item - as a collaboration/.

As I wrote, this already helped a lot. In the meantime I changed names of the all item view and custom view, as well as I set the custom view as default view. With this, running the above code, it works now as I expected!!!

Thanks again for the help ! :-)