Get Free Trial

How to get underling actual values of filter fields when using getFilter and getReportFilters

Re-Open
Parmod asked on May 15, 2021

Hi Flexmonster Team,

When I am trying to fetch the actual value of filters using using getFilter and getReportFilters, I am getting values as i.e http://jsfiddle.net/flexmonster/mq32shu2/

{
"members": [
"category.[bikes]",
"category.[cars]"
]
}

How to convert above response to 

{
"members": [
"Bikes",
"Cars"
]
}

Regards,
Parmod

9 answers

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster May 17, 2021

Hello,
 
Thank you for posting on our forum.
 
We want to explain that field’s member is represented as a pair of the member’s and field’s names.
It allows identifying members with the same name among different fields.
 
Still, you can achieve the desired functionality by combining getFilter or getReportFilters with another API call provided by Flexmonster – getMembers. It returns a list of members for the specified hierarchy. The returned members also contain their captions (“Bikes”, “Cars”) in addition to their unique name (“category.[bikes]”, “category.[cars]”). It allows retrieving corresponding captions and use them instead of the unique names returned by default.
 
We have modified the mentioned JSFiddle to demonstrate this approach: http://jsfiddle.net/flexmonster/756waudn/.
 
Please let us know if it works for you.
Looking forward to your feedback.

Regards,
Illia

Public
Parmod May 17, 2021

Hi Illia,

Just few more question. We are using ‘Custom Datasource API’

1. Do I need the set the hierarchy in response from /field request?
2. What is the difference between caption and unique name in the object retrieve using getMembers?
3. For certain fields we are setting the id for /member request. But using above mention translateToCaption we are not able to get the id, instead we get the value?
Regards,
Parmod

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster May 18, 2021

Hello,
 

  1. The hierarchy property is used to configure multilevel hierarchies as described in the /fields request reference: /fields request | Flexmonster. Use it if you need to specify the level of the multilevel hierarchy.
  2. The caption defines how the member is shown to the final user. In its turn, the uniqueName is used to represent members in the internal structure.
  3. When specifying a member’s id, it replaces its uniqueName in the internal structure. Therefore, you should be able to use the same method translateToCaption. If it does not work for your case for some reason, please prepare an example that would demonstrate the issue.

Looking forward to hearing your feedback.
 
Regards,
Illia

Public
Parmod May 18, 2021

Hi Illia,

I have added JSFiddle to demonstrate our approach: https://jsfiddle.net/g9nta2em/ and https://jsfiddle.net/g9nta2em/1/
One the console we are getting this error

Uncaught TypeError: members.find(...) is undefined

  To resolve the above issue we have modified the function as below

function translateToCaptions(uniqueNames, members) {
uniqueNames.forEach((memberUniqueName, i) => {
uniqueNames[i] = members.find(member => memberUniqueName == member.parentMember.replace('(all member)', member.uniqueName)).caption;
});
return uniqueNames;
};

Regards,
Parmod

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster May 19, 2021

Hello,
 
We have checked the mentioned JSFiddle and noted an exception in the console. It is because the getMember method returns nothing in the context of the custom data source API. Instead, the received members are passed as an argument to the function’s callback.
 
We have modified the provided JSFiddle so that no exceptions arise, and all the filters are displayed correctly: https://jsfiddle.net/flexmonster/yo35gn7j/.
 
Could you please clarify if this approach works for you now?
Looking forward to your feedback.
 
Kind regards,
Illia

Public
Parmod May 19, 2021

Hi Illia,

The result which I am getting is

{
"exclude": [
"February",
"January"
]
}

But the expected result is

{
"exclude": [
2,
1
]
}

The select request is:

{
"type": "select",
"index": "nonexistent_index",
"query": {
"aggs": {
"by": {
"rows": [
{
"uniqueName": "Date##Calendar##Calendar Month"
}
]
},
"values": [
{
"func": "sum",
"field": {
"uniqueName": "Weight"
}
}
]
},
"filter": [
{
"field": {
"uniqueName": "Date##Calendar##Calendar Month"
},
"exclude": [
{
"member": "1"
},
{
"member": "2"
}
]
}
]
},
"page": 0
}

Regards,
Parmod

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster May 19, 2021

Hello,

Thank you for the clarification.
 
If we understand correctly, the desired scenario would be the following: if the member does not have any id, return its caption. Otherwise, if a member has an id, return a uniqueName containing the id itself.
 
In this case, the only option would be to check if the member’s unique name meets the default format. If it does not, treat it as an identifier. Otherwise, use caption instead. We have complemented the JSFiddle to demonstrate this approach: https://jsfiddle.net/flexmonster/wad4hjsc/.
Please note that this approach implies that the id’s format must differ from the default unique name’s format: field.[member].
 
Looking forward to hearing your feedback.
 
Regards,
Illia

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster May 26, 2021

Hello,
 
We are wondering if the provided approach works for you.
 
Looking forward to hearing your feedback.

Regards,
Illia

Public
Parmod May 26, 2021

Hi Illia,

It is working, Thanks for all the help 🙂

Regards & Thanks
Parmod

Please login or Register to Submit Answer