Survey banner
The Dataiku Community is moving to a new home! We are temporary in read only mode: LEARN MORE

Send record count in body of email

madisondunn8
Level 1
Send record count in body of email

Hello, I'm trying to do something very similar to this situation: https://community.dataiku.com/t5/Using-Dataiku/Returning-the-Metric-Record-Count-in-a-Slack-message/... but in an email message and I cannot get it to work. I have a dataset called "RECORDS" and in the scenario, I am first running the metrics, then in a step after sending an email, trying to call the record count. Within my dataset RECORDS, I believe I have the record count metric turned on but when I try to call it in my email step using this: 

${filter(parseJson(stepOutput_the_metrics)[‘PROJECT_NAME.RECORDS’].computed, x, x.metricId == ‘records:COUNT_RECORDS’)[0].value}

When I run the step, I always get the error ' freemarker.core.ParseException
Syntax error in template "tmpl0" in line 8, column 40: Lexical error: encountered "\u2018" (8216), after "".' 

Any suggestions? I'm very confused about how to get the output itself from the metrics computation (${stepOutput_the_metrics}) as nothing returns when I call that. Please advise. 


Operating system used: Windows

0 Kudos
2 Replies
AlexT
Dataiker

Hi,

I am unsure if it's an issue with the syntax with the exprenssion or an issue with freemarker.

You can instead just set variable step before, set a scenario variable with the metric and then only include the scenario name in your email template e.g ${variable_name}


Screenshot 2023-08-03 at 4.28.08 PM.png

toNumber(filter(parseJson(stepOutput_the_metrics)['DKU_TUTORIAL_TIME_SERIES_PREPARATION.orders_by_date_by_order_date_NP']['computed'], x, x["metricId"]=="records:COUNT_RECORDS")[0].value)

 
The DKU_TUTORIAL_TIME_SERIES_PREPARATION -> Project ID
orders_by_date_by_order_date is the dataset name it's not a partitioned dataset needs to add _NP at the end.

In my test I am just sending a webhook and I can confirm the variable is being passed:


 

Screenshot 2023-08-03 at 4.30.34 PM.pngScreenshot 2023-08-03 at 4.30.00 PM.png

0 Kudos
Turribeach

Hi, I think Alex has now covered all the problems your expression had. I checked with mine as well and it's the same:

toNumber(filter(parseJson(stepOutput_Compute_Metrics)['PROJECT_ID.DATASET_ID_NP']['computed'], x, x["metricId"]=="records:COUNT_RECORDS")[0].value)

A few other things to highlight:

  1. Project ID and Dataset Name are case sensitive. Make sure you get the correct values as Project ID is not the same as Project Name. The easiest way to get the correct Project ID and Dataset Name is to open the dataset from the flow and then copy the Project ID and Dataset Name from the browser URL (http://your_server/projects/PROJECT_ID/datasets/DATASET_NAME/explore/
  2. Make sure the "Evaluated variables" is set to ON on the define variables step
  3. You can then refer to the variable name using the name you defined in the define variables using ${variable_name} in your email template 

I also wrote a more extended post showing in more detail how to build these expressions step by step. Have a look at this post and scroll down for more details:

https://community.dataiku.com/t5/What-s-New/Want-to-Control-the-Execution-of-Scenario-Steps-With-Con...

 

0 Kudos