Message Boards
How can we use filter in graphql (/o/api) to filter based on custom fields
Bhargav R Vaghasiya, modified 1 Year ago.
How can we use filter in graphql (/o/api) to filter based on custom fields
New Member Posts: 3 Join Date: 10/9/20 Recent Posts
I need to fetch all users from the Liferay (GraphQL) based on the value of the custom field
I am using GraphQL in Liferay from /o/api
I am only able to filter the data based on email ID and user ID, here is my query for that
=======================================================================================
query {
userAccounts(filter:"emailAddress eq 'test@liferay.com'"){
items{
emailAddress
id
name
customFields{
name
customValue{
data
}
}
}
}
}
=======================================================================================Result:======================================================================================={
"data": {
"userAccounts": {
"items": [
{
"emailAddress": "test@liferay.com",
"id": 20126,
"name": "Test Test",
"customFields": [
{
"name": "Speciality",
"customValue": {
"data": [
"Cardiologia"
]
}
}
]
}
]
}
}
}
=======================================================================================
but i want to filter based on value of the custom fieldName of the custom field: "Speciality" and possible (selectable) value is {Cardiologia, Dermatologia, vagh3}I have tried lot's of way to achieve this but every time failed........I am loosing my hopeCan we filter the data based on custom fields? and if Yes, then how?????
I am using GraphQL in Liferay from /o/api
I am only able to filter the data based on email ID and user ID, here is my query for that
=======================================================================================
query {
userAccounts(filter:"emailAddress eq 'test@liferay.com'"){
items{
emailAddress
id
name
customFields{
name
customValue{
data
}
}
}
}
}
=======================================================================================Result:======================================================================================={
"data": {
"userAccounts": {
"items": [
{
"emailAddress": "test@liferay.com",
"id": 20126,
"name": "Test Test",
"customFields": [
{
"name": "Speciality",
"customValue": {
"data": [
"Cardiologia"
]
}
}
]
}
]
}
}
}
=======================================================================================
but i want to filter based on value of the custom fieldName of the custom field: "Speciality" and possible (selectable) value is {Cardiologia, Dermatologia, vagh3}I have tried lot's of way to achieve this but every time failed........I am loosing my hopeCan we filter the data based on custom fields? and if Yes, then how?????
Luis Miguel Barcos, modified 3 Years ago.
RE: How can we use filter in graphql (/o/api) to filter based on custom fie
New Member Posts: 5 Join Date: 6/15/18 Recent Posts
Hi Bhargav Vaghasiya.
I was investigating about that and I found this: https://github.com/liferay/liferay-portal/blob/master/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/odata/entity/v1_0/UserAccountEntityModel.java
It seems like the filter for custom fields for user accounts is not supported yet.
But, if you have created your custom field searchable, you can search the Speciality by its value. I mean, you can do something like this:
query {
userAccounts(search: "dermatologia") {
items {
emailAddress
id
name
customFields {
name
customValue {
data
}
}
}
}
}
And received the following response
{
"data": {
"userAccounts": {
"items": [
{
"emailAddress": "luismitest@liferay.com",
"id": 38306,
"name": "luismi test",
"customFields": [
{
"name": "Speciality",
"customValue": {
"data": "Dermatologia"
}
}
]
}
]
}
}
}
Hope this helps you.
I was investigating about that and I found this: https://github.com/liferay/liferay-portal/blob/master/modules/apps/headless/headless-admin-user/headless-admin-user-impl/src/main/java/com/liferay/headless/admin/user/internal/odata/entity/v1_0/UserAccountEntityModel.java
It seems like the filter for custom fields for user accounts is not supported yet.
But, if you have created your custom field searchable, you can search the Speciality by its value. I mean, you can do something like this:
query {
userAccounts(search: "dermatologia") {
items {
emailAddress
id
name
customFields {
name
customValue {
data
}
}
}
}
}
And received the following response
{
"data": {
"userAccounts": {
"items": [
{
"emailAddress": "luismitest@liferay.com",
"id": 38306,
"name": "luismi test",
"customFields": [
{
"name": "Speciality",
"customValue": {
"data": "Dermatologia"
}
}
]
}
]
}
}
}
Hope this helps you.