1

I have a document library with Document Sets, and inside document sets I have files.

I need a CAML Query to return ONLY the files, but I need to know to which Document Set each file belongs to.

I am using CAML Designer and used all fields, but I cant seem to find if this is easily possible.

function GetRelatedBillingDocumentsFromList(selectProperties, currentBillCyclePath, clientCode, jobCodes, engagementCode, enhanceFunctions) {
                $log.info("Retrieving related billing documents for bill cycle with name [" + currentBillCyclePath + "]");                  
                var deferred = $q.defer();
                var webUrl = _spPageContextInfo.webAbsoluteUrl;
                var viewFields = spService.ConvertSelectPropertiesToViewFields(selectProperties);
                // query must return the documents for the same client but in other bill cycles not the current one
                var camlQuery = '<View>' +   viewFields + 
                        '<Query>' +
                            '<Where>' +
                                '<And>' +
                                    '<Eq>' +
                                        '<FieldRef Name="ClientCode" />' +
                                        '<Value Type="Text">'+ clientCode + '</Value>' +
                                    '</Eq>' +
                                    '<Neq>' +
                                        '<FieldRef Name="ContentType" />' +
                                        '<Value Type="Computed">Bill Cycle</Value>' +
                                    '</Neq>' +
                                '</And>' +
                            '</Where>' +
                            '<QueryOptions>' +
                            '    <ViewAttributes Scope="RecursiveAll" />' +
                            '</QueryOptions>' +
                        '</Query>' +
                    '</View>';

                var billCyclesListId = "{c23bbae4-34f7-494c-8f67-acece3ba60da}";                    
                spService.GetListItems(billCyclesListId, camlQuery, selectProperties)
                .then(function(listItems) {                 
                    var listItemsWithValues = [];
                    var promises = [];
                    if(listItems) {
                        var enumerator = listItems.getEnumerator();
                        while (enumerator.moveNext()) {
                            var listItem = enumerator.get_current();
                            var listItemValues = [];                                
                            selectProperties
                            .forEach(function(propertyName) {                               
                                var value = listItem.get_item(propertyName);
                                listItemValues[propertyName] = value;
                            });

                            listItemsWithValues.push(listItemValues);
                        }

                        var cname = getContentTypeOfCurrentItem(listItemValues["ID"].toString());
                        listItemsWithValues["Document Type"] = cname;
                    }

                    listItemsWithValues.forEach(function(listItem) {
                        var fileDirRef = listItem["FileRef"];
                        var id = listItem["ID"];
                        var serverUrl = _spPageContextInfo.webAbsoluteUrl.replace(_spPageContextInfo.webServerRelativeUrl,"");                          
                        var dispFormUrl = serverUrl + fileDirRef + "/DispForm.aspx?ID=" + id;
                        listItem["FileRef"] = dispFormUrl;
                    });

                    var enhancedListItemValues = spService.SpSearchQuery.EnhanceSearchResults(listItemsWithValues, enhanceFunctions);                       
                    deferred.resolve(listItemsWithValues);
                })
                .catch (function (message) {
                    deferred.reject();
                });

                return deferred.promise;
            }

where CAML query is:

"<View><ViewFields><FieldRef Name="ID" /><FieldRef Name="FileLeafRef" /><FieldRef Name="Title" /><FieldRef Name="FileRef" /><FieldRef Name="JobCodesMulti" /><FieldRef Name="ClientsSearchMulti" /><FieldRef Name="BillNumber" /><FieldRef Name="Bill_x0020_date" /><FieldRef Name="WIP_x0020_Out_x0020_Amount" /><FieldRef Name="Author" /><FieldRef Name="FileRef" /></ViewFields><Query><Where><And><Eq><FieldRef Name="ClientCode" /><Value Type="Text">123</Value></Eq><Neq><FieldRef Name="ContentType" /><Value Type="Computed">Bill Cycle</Value></Neq></And></Where><QueryOptions>    <ViewAttributes Scope="RecursiveAll" /></QueryOptions></Query></View>"

Your Answer

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

Browse other questions tagged or ask your own question.