Need a special offer?Find out if your project fits.
+

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

Answered
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

14 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

Public
Parmod April 27, 2022

Hi Flexmonster Team,

{
"type": "select",
"index": "MyTestPivot",
"query": {
"aggs": {
"by": {
"rows": [
{
"uniqueName": "Month"
}
]
},
"values": [
{
"func": "sum",
"field": {
"uniqueName": "Weight"
}
}
]
},
"filter": [
{
"field": {
"uniqueName": "Date"
},
"query": {
"between": [
1648751400000,
1651084199999
]
}
}
]
},
"page": 0
}

When I am trying to fetch the actual value of filters using using getFilter and getReportFilters,

{
"field": {
"uniqueName": "TDate"
},
"query": {
"between": [
"2022-04-01",
"2022-04-27"
]
}
}

How to convert the response to

{
"field": {
"uniqueName": "TDate"
},
"query": {
"between": [
"1648751400000",
"1651084199999"
]
}
}

Regards,
Parmod

Public
Maksym Diachenko Maksym Diachenko Flexmonster April 28, 2022

Hi, Parmod!

Thank you for writing to us.

The logic behind returning the string dates in the getFilter method is to make them more readable. You can also use this date format for configuring filters inside the report or via the setFilter API call.

We recommend preprocessing the data from the getFilter API call to change the time format. You can convert the dates to UNIX timestamps via Date.parse(date) method. Here is a JSFiddle example: https://jsfiddle.net/flexmonster/0uv2xwza/.

Please let us know if this helps.

Best Regards,
Maksym

Public
Parmod April 28, 2022

Hi Maksym,

Flexmonster automatically convert the start date to Start of day and end date to End of the day.

we need to format all the request exactly to flexmonster provided request format
i.e

{
  "field": {
    "uniqueName": "TDate"
  },
  "query": {
    "between": [
      "1648751400000",
      "1651084199999"
    ]
  }
}

Regards,
Parmod

Public
Maksym Diachenko Maksym Diachenko Flexmonster April 29, 2022

Hi, Parmod!

Thank you for your reply.

The Flexmonster date filters are only storing the dates inside the report, and they are parsed as dates with the time 00:00 (start of the day). To get the end of a day UNIX time, we recommend adding the number of milliseconds in one day minus one:

// milliseconds * seconds * minutes * hours 
let oneDayUnix = 1000 * 60 * 60 * 24;
let endDayUnix =  Date.parse(date) + (oneDayUnix - 1);

Please see the modified sample from our previous reply, where the date with the day's last millisecond is returned: https://jsfiddle.net/flexmonster/zc74p1j0/

Hope this answer helps you.

Best Regards,
Maksym

Public
Maksym Diachenko Maksym Diachenko Flexmonster May 5, 2022

Hi, Parmod!

Hope you are doing well.
We were wondering if our response helped you with your question. Looking forward to hearing from you.

Best Regards,
Maksym

Please login or Register to Submit Answer