I'd like to add a new UDF to my workspace using th...
# gd-beginners
p
I'd like to add a new UDF to my workspace using the entity API that limits a particular metric to users in a certain account (CLIENT_ORG_KEY). I'm consistently getting the following error on my call to POST /api/v1/entities/workspaces/{workspaceId}/userDataFilters:
Copy code
{
  "detail": "The MAQL query='SELECT SUM(TRANSACTION.TRANSACTION_UNITS) WHERE TRANSACTION.CLIENT_ORG_KEY = \"4e947d2f-8a21-43fa-a905-397fa2a4c1c5\"' could not be parsed. Character on position 13 in line 1: extraneous input 'SELECT' expecting {'bottom', 'case', 'cume_dist', 'dense_rank', 'false', 'first_value', 'if', 'last_value', 'next', 'not', 'null', 'percent_rank', 'previous', 'rank', 'report', 'row_number', 'runavg', 'runmax', 'runmin', 'runsum', 'runstdev', 'runstdevp', 'runvar', 'runvarp', 'this', 'top', 'true', 'day', 'dayofweek', 'dayofmonth', 'dayofyear', 'hour', 'hourofday', 'minute', 'minuteofhour', 'month', 'monthofyear', 'quarter', 'quarterofyear', 'year', 'week', 'weekofyear', String, '{', '(', '-', '+', ZERO, Natural, Real, Identifier}",
  "status": 400,
  "title": "Bad Request",
  "traceId": "13ab3b531fc24a86"
}
The request body looks like this:
Copy code
{
  "data": {
    "type": "userDataFilter",
    "id": "ca-sco-transaction-units",
    "attributes": {
      "maql": "SELECT SUM(TRANSACTION.TRANSACTION_UNITS) WHERE TRANSACTION.CLIENT_ORG_KEY = \"4e947d2f-8a21-43fa-a905-397fa2a4c1c5\"",
      "title": "CA SCO Transaction Units"
    },
    "relationships": {
      "user": {
        "data": {
          "id": "ca_test1",
          "type": "user"
        }
      }
    }
  }
}
I've tried several variations of the MAQL but can't seem to make the MAQL validator happy (error is the same each time). Can someone suggest what I'm doing wrong or provide an example of the valid MAQL in this case? A snapshot of my model is attached.
1
m
Hi Pete, the User Data FIlters definition should only contain the condition (the expression without the WHERE or SELECT keyword). So for example in the example mention in the documentation it is
"{label/l_linestatus} = \"O\"",
Also, in the MAQL condition I believe you should use the identifiers of GoodData objects (facts/attributes/labels) as they are used in the metric editor - that is in the
{}
brackets and with some prefix.based on the type of the object i.e.
{label/transaction.client_org_key}
The UDFs once set for a user are applied to the whole workspace, not just a particular metric. So if you apply the filter to the user, any query which they execute (and will be compatible in the LDM with the condition) will get filtered. Different users can then look at the same insight and see different data based on what UDFs they have.
🙌 1
p
Thank you, Michal. That did it. And thanks for the explanation as well. 😀
1