I am trying to insert some CAML into my site and I am not sure how to do so.

I have been looking around at the available Web Parts (and other areas) to allow me to add a CAML query to my site, but I cannot find one.

Thanks in advance.


If you are using SharePoint on-prem and have the option to add a Script Editor Web Part, you can add such a web part and write plain HTML in it like this:

<link href="/SiteAssets/styles/mystyles.css" rel="stylesheet" />
<div id="results">Waiting for results...</div>
<script src="/SiteAssets/scripts/myscript.js"></script>

The first line is optional, just a link to a css file that can style your results. The second line is a div used to display the result of your query. The third line calls your JavaScript in which you issue the CAML query and update the div with your result, something like this:

document.getElementById("results").innerHTML = <your result here>

If you are using SharePoint Online, I would recommend you to use SharePoint FrameWork instead.

| improve this answer | |

You can use script editor web part to add JSOM script with CAML query


function getUserData() {
var employeeList = clientContext.get_
var userTitle = user.get_title();
var collListItem;
var oListItem;
var camlQuery = new SP. CamlQuery ();
"<Where>" +
"</Where>" +
    collListItem = employeeList.getItems(
    clientContext.load(collListItem, 'Inc
Function .createDelegate( this , suc
Function .createDelegate( this , err
function successHandler() {
var listItemEnumerator = collList
while (listItemEnumerator.moveNext
var oListItem = listItemEnumerato
        alert(oListItem.get_item( 'empNick
//userDepartment.innerHTML = oLis
function errorHandler() {
        userDepartment.innerHTML = "Reque
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.