Search This Blog

Saturday, August 12, 2017

Return function in Jquery

Call Function :

Var strbname= GetAllFileCountInParticularFolder(“NGO/Ram”,element);


Function :
function GetAllFileCountInParticularFolder(folderName,element)
{
    var TotalfileCount=0; 
    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetFolderByServerRelativeUrl('" + folderName + "/')/Files?$orderby=Title&$expand=ListItemAllFields,ListItemAllFields/ParentList", //?$expand=Files",
        type: "Get",
        headers: {
            "accept": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val(),
            "content-Type": "application/json;odata=verbose"
        },
        success: function(dataresult) {
            $.each(dataresult.d.results, function(key, value) {
            if (value.Name != "Forms") {
            if(value.ListItemAllFields["OData__ModerationStatus"] == 0)
            {
               
              TotalfileCount+=1;
             $(element).append( "<strong>( "+TotalfileCount+" )</strong>" );
            }
            }
            });
         
        },
        error: function(error) {
            //                                                alert(JSON.stringify(error));
        }
    });
   
  return TotalfileCount;
}


No comments:

Post a Comment