Quantcast
Channel: All Developer posts
Viewing all articles
Browse latest Browse all 48469

Re: Construct Filter with Javascript function

$
0
0

This is now working for operators besides "In". Modified code: 

function advancedFilter(table, column, logicalOperator, operator, value){
 if (logicalOperator == undefined || logicalOperator == "" || logicalOperator == null) {
logicalOperator = "And";
}
if (operator == undefined || operator == "" || operator == null) {
operator = "Is";
}
if (value == undefined || value == "" || value == null) {
value = 0;
} if (operator == "In") { return filter = { $schema: "http://powerbi.com/product/schema#advanced", target: { table: table, column: column }, logicalOperator: logicalOperator, conditions: [ { operator: operator, values: value } ] }; } else { return filter = { $schema: "http://powerbi.com/product/schema#advanced", target: { table: table, column: column }, logicalOperator: logicalOperator, conditions: [ { operator: operator, value: value } ] }; } }

Called in the view: 

var arr = [104, 102, 117];
var useFilter = advancedFilter(table, column, "", "In", arr);

Pushed to the report filters:

                report.on('loaded', event => {
                    report.getFilters()
                    .then(filters => {
                        filters.push(useFilter);
                        return report.setFilters(filters);
                    })
                })

It may also be worth noting that I have the function in a separate javascript file that I am referencing in the view. Here is what returns in the alert text box: 

{  
   "$schema":"http://powerbi.com/product/schema#advanced",
   "target":{  
      "table":"SiteInfo",
      "column":"SiteId"
   },
   "logicalOperator":"And",
   "conditions":[  
      {  
         "operator":"In",
         "values":[  
            104,
            102,
            117
         ]
      }
   ]
}

I still get the error message in the developer console on the web page: Uncaught (in promise): Array[4].  

Array[4]
0
:
Object
message
:
"operator is invalid. Not meeting required constraint"
__proto__
:
Object
1
:
Object
message
:
"values is invalid. Not meeting required constraint"
__proto__
:
Object
2
:
Object
message
:
"conditions.0.value is invalid. Not meeting required constraint"
__proto__
:
Object
3
:
Object
message
:
"filter is invalid"

What do you suggest?


Viewing all articles
Browse latest Browse all 48469

Trending Articles