Get your SP CAML query by CSOM

When you don't know the syntax of CAML (Colloborative Application Markup Language) . How can you achieve via CSOM ?

With this technique,  You don't need the tools like U2U CAML Builder or Any other CAML Query builders.

Step1 : Create the Test View with what you would like to achieve . For example,  I have created a view called Test View and the query looks below with simple where condition with And.

Step 2 : Create a Console Application. Code like bellow .

Now your viewCAML string will be the query, you can use it in your code. 

You can further format like below :

<Where>
<And>
<Eq>
<FieldRef Name="Year"/><Value Type="Text">{Value}</Value>
</Eq>
<Eq>
<Field Ref Name="Customer"><Value Type="Text">{Value}</Value>
</Eq>
</And>
</Where>

Don't forget to prep-end like below example "<View><Query></View></Query> in your JavaScript while querying 

JS Code to get the list items via JSOM

https://msdn.microsoft.com/en-us/library/office/hh185007(v=office.14).aspx#sectionSection0

Samir Shikalgar

Manager | Consultant | Architect | Microsoft 365 | SharePoint | Power Apps | Power Automate | Power BI

8 年

Wonderful example. Thanks for sharing.

要查看或添加评论,请登录

Rakesh Kolloju的更多文章

社区洞察

其他会员也浏览了