I have one field manage metadata which name is department and its has 3 value HR, Admin and account so I want to filter out Admin data and display count of results. I am using SharePoint online.
-
1Hi @vinia, did you try my solution given below? Is it working for you?– Ganesh Sanap - MVPCommented Jun 8, 2023 at 8:00
-
Yes working but i want also looking for all manage metadata list fields– vinia shahCommented Jun 9, 2023 at 5:02
-
1Great, glad it worked for you.– Ganesh Sanap - MVPCommented Jun 9, 2023 at 5:32
-
Please Upvote(^) and accept as an Answer as it helped you & it will help others with similar question in future to find the correct answer easily.– Ganesh Sanap - MVPCommented Jun 9, 2023 at 5:33
1 Answer
If you have only one managed metadata column in your SharePoint list, you can use API call like:
_api/web/lists/GetByTitle('EInfochips')/items?$filter=TaxCatchAll/Term eq 'Admin'
Source: Filter a SharePoint list on a Managed Metadata field in a REST based client application
Also, you can get the list items based on managed metadata column filter using POST
API call and CAML query like:
var listName = "EInfochips";
var taxoField = "Department";
var taxoValue = "Admin";
restUrl = appWebUrl + "/_api/web/lists/getbytitle('" + listName + "')/GetItems(query=@v1)?@v1=" +
"{\"ViewXml\":\"<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef%20Name='" +
taxoField + "'/><Value%20Type='TaxonomyFieldType'>" + taxoValue + "</Value></Eq></Where></Query></View>\"}" +
select;
$.ajax(
{
url: restUrl,
method: "POST",
headers: {
"Accept": "application/json; odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
}
}
);
Source: Rest Query Managed Metadata Filter
Where Department
is internal name of your managed metadata column. You can get the internal name of your column by following this article: How to find the Internal name of columns in SharePoint Online?
Once you get the array of results back from API call, you can get the count of returned results by using .length
property or array like:
console.log("No. of results: " + dataresults.length);