I have a caml query that I'm concatenating with a javascript variable of type string. It queries the column names 'Audience' and returns the first 3 ordered by the newest.
The variable subsite gets the current subsite unless there is none and therefore is set to the 'Home Page' audience. (An option in the column) Is there a way to do this in JS?
var subsite = window.location.pathname.split('/')[1];
if(subsite.length == 'SitePages')
{
subsite = 'Home Page';
}
var camlQuery = new SP.CamlQuery();
var query = '<Query>
<Where>
<Eq>
<FieldRef Name='Audience' />
<Value Type='MultiChoice'>'+subsite'</Value>
</Eq>
</Where>
<OrderBy>
<FieldRef Name='Created' Ascending='False' />
</OrderBy>
</Query>';
camlQuery.RowLimit = 3;
camlQuery.set_viewXml(query);
listItems = list.getItems(camlQuery);
context.load(listItems);
context.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded),
Function.createDelegate(this, onQueryFailed));
function onQuerySucceeded(sender, args){
}
ctx.get_web().get_title()
? It's more reliable than the URLsubsite.length
will be a number, so it'll never equal'SitePages'