Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Adding Another Condition to my CAML Statement

$
0
0

I have the following CAML that a developer wrote for me. I would like to add an additional EQ News Category Type to the CAML query in order to return both the News & Memos type of News.

                 

    try {
var oInstance = this;
var camlQuery = "";
CSPDebug.write("HomeNews["+oInstance.appletKey+"].generateCAML(dcnIndex='"+dcnIndex+"' kwSearchTerm='"+kwSearchTerm+"')");

var conditions = [];

       if ((oInstance.model.dcn[dcnIndex]["_fieldKWS"])&&(kwSearchTerm)) {
            var kwConditions = [];
            var words = kwSearchTerm.split(' ');
            $.each(oInstance.model.dcn[dcnIndex]._fieldKWS, function(index,item) {
           $.each(words, function(index2,word) {
if (word)
               kwConditions.push(CSPCaml.CreateCAMLStatements("Contains" ,item,"text",word));
});
                });
            conditions.push(CSPCaml.MergeCAMLStatements(kwConditions, "or" ))
            }
conditions.push(CSPCaml.CreateCAMLStatements("Leq", "Date1", "DateTime", CSPDate.FormatDate(new Date(), "DATEFMT_SHAREPOINT")));
conditions.push(CSPCaml.CreateCAMLStatements("Eq", "NewsCategory", "Choice", "News"));

        camlQuery = "<Query>";
        if (conditions.length)
                        camlQuery += "<Where>" + CSPCaml.MergeCAMLStatements(conditions, "and" ) + "</Where>";
        camlQuery += "<OrderBy><FieldRef Name='SortOrder' Ascending='FALSE' /></OrderBy>";
        camlQuery += "</Query>";
        CSPDebug.write("HomeNews["+oInstance.appletKey+"] Generated caml query for dcnIndex='"+dcnIndex+"' with kwSearchTerm='"+kwSearchTerm+"' CAML='"+camlQuery+"'");
return camlQuery;
} catch(e) { ExceptionConnector.Handler(EXX.CreateViewModelException("HomeNews", "generateCAML ", e));}
}


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>