Accessing sharepoint from caml - sharepoint

How can I add javascript to my CAML code?
For example, I want to calculate some rates/dates according to local field on Sharepoint list.
I want to set value of field according to the javascript result.
Any Idea ?
Poli .

You can add JavaScript to your page, not to CAML.
CAML is used to query Sharepoint lists.
The results will be rendered as HTML
Have a look at the rendered HTML and go from there.

You can't really "add" javascript code to a CAML query because CAML queries run on the server where as javascript runs client side.
Say you have a query like this :
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name='FieldName' /><Value Type='Text'>TestValue</Value></Eq></Where>";
When you run your query :
SPListItemCollection items = list.GetItems(query);
You will end up with your items. This is where you can modify them and run your logic code (in your backend code).
For example :
foreach(SPListItem item in SPListItemCollection)
{
int rate = item["SomeField"].ToString() + item["SomeOtherField"].ToString();
//Do whatever you want with the result
}

Related

How to get data from a caml results using caml

The scene is:
I've got items using caml on a list view(e.g. previewlist), and I'll have to query again from these items, is it possible using caml to query from SPListItemsCollection? as MSSQL we can do select * from(select * from tablename), but how can we finished that in caml ?
And if that impossible, i'll have to search from those items first and then add the result to a splist or a spview, anybody knows how to do this? (yeah, two diff ideas).
Maybe you can try using SourceQuery property, retrieve original query and build new one using operator to combine two queries?

SPQuery : Difference between Query and ViewXml properties?

Hello SharePoint developpers !
I can't deeply understand the difference between Query and ViewXml properties in the SPQuery object. In the msdn documentation, it's written :
Query : Gets or sets the inner XML
used in the query.
ViewXml : Gets or sets the XML schema that defines the
view.
it seems to me that ViewXml is appropriate to filter the fields you want to retrieve... I'm not sure.
So what's the difference ? in which situations should we choose the first over the second ?
How SharePoint is treating those queries ..
Mystery remains for me so if someone could throw some light on it ?
thank you...
ViewXml completly describes query. It can contain Query, ViewFields, RowLimit elements and many more. For SPQuery you should better use corresponding properties (Query, ViewFields, RowLimit etc), and ViewXml will be generated automatically. You can test it by setting this properties for SPQuery object and then look to ViewXml. You should set ViewXml manually if you need to set some specific properties (but as I remember they all can be set using SPQuery properties).

How to get all items in a search scope in SharePoint 2010?

I thought I could just do something like this:
SPQuery oQuery = new SPQuery();
oQuery.ViewAttributes = "Scope='MyScope'";
SPListItemCollection collListItems = oList.GetItems(oQuery);
but it is pulling back a bunch of stuff that is not in the scope. Is there a different way I should be doing this?
You are confusing SPQuery, which a list querying class, based on CAML, and the search API. Take a look into FullTextSqlQuery, which is the class you really should work with.

problem with SPQuery for whole sitecollection?

HI, Can we use SPQuery to query whole site collection. Means I have a list which is in different site so is it possible to use SPQuery for that or I need to use SPSiteDataQuery.
I know SPSiteDataQuery would work in this case but I don't wanna search all the lists as I know the name of the list and in SPSiteDataquery i can't mention the list name and in my case list name is unique in whole site collection. If not SPQuery whats the best method to query my list . I don't wana use Guid over here....
Any suggestions?
Thanks,
If you know the exact position of the list (i.e. the (sub)web it is in), you can just use
using(SPWeb otherWeb = SPContext.Current.Site.OpenWeb("urlofweblistisin"))
{
SPList yourList = otherWeb.Lists["YourListName"];
SPListItemCollection = yourList.GetItems(yourSPQuery);
}

CAML GroupBy usage when querying a list using the SPQuery or SPSiteDataQuery object

I'm not sure how to use the GroupBy clause when querying a list. The SPListItemCollection or datatable looks exactly the same regardless of the groupby clause.
SPQuery query = new SPQuery();
query.Query = "<GroupBy><FieldRef Name=\"Area\"/></GroupBy>";
DataTable result = list.GetItems(query).GetDataTable();
// result.Rows.Count = Same as ungrouped query
Is GroupBy only supported by Lists.asmx webservice?
Found a reference on MS Social which suggests it's not supported on the SPSiteDataQuery object http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/ab8df6f5-35a0-401e-88cb-3eb31362bf0c/
I believe that clause is more related to how the grouping will be displayed in the UI. As far as the data returned goes, you might/should get some sorting but that's about it.
Regarding the UI, there is the GroupLimit element which limits how many groups are returned. There is also the Collapse element which has no meaning when used with SPQuery.
How were you hoping the data would be different?

Resources