Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Hello,
Im using the step Export notebook in a scenario step and sending it as an attached html file using mail reporter. The problem is that the exported notebook will have always “notebook.html” as its name.
Any idea on how to keep the initial name of the notebook in the project or rename it with a global variable in the scenario steps. The idea is to use the date of the execution of the scenario to rename the Exported file “control_outcome_2022-06-15.html” for example.
Thanks,
Operating system used: Windows 10
Hi @Sidiya ,
There's no way to change the name of the attached notebook, but if your goal is to get the date of execution, there are a couple other ways that you can get it:
from datetime import date
current_day = date.today()
print('Executed on:', current_day)
import json
from datetime import date
# Compute your additional variables from the list of report items
# and return them as a dictionary.
def get_variables(items_json, scenario_run_json, step_run_output_json):
scenario_run = json.loads(scenario_run_json)
# POSIX timestamps (in milliseconds) indicating the times that the
# scenario started and ended.
time_started = scenario_run['start']
time_ended = scenario_run['end']
# Convert the timestamps to dates
date_started = date.fromtimestamp(time_started / 1000)
date_ended = date.fromtimestamp(time_ended / 1000)
# Return a dict of custom variables
return {
'scenarioStarted': date_started.isoformat(),
'scenarioEnded': date_ended.isoformat()
}
This will create 2 new variables called ${scenarioStarted} and ${scenarioEnded}. You can use them in the subject or the body of the email.
If you have any questions, feel free to let me know.
Thank you,
Zach
Hello,
Thank you for the answer.
Can I at least keep the initial name of the notebook as it is the case when the notebbok is exported manually ?
I just find it a little bit frustrating to have the expoprted file always named as 'notebook.html'.
Thanks for your help !
Hi @Sidiya ,
You can obtain the name of the notebook similarly to method 2 that I described in my previous post. You'll want to use the following code for the custom variable:
import json
# Compute your additional variables from the list of report items
# and return them as a dictionary.
def get_variables(items_json, scenario_run_json, step_run_output_json):
scenario_run = json.loads(scenario_run_json)
# Get the name of the first attached notebook in the first reporter
# in the scenario.
notebook_id = scenario_run['scenario']['reporters'][0]['messaging']['configuration']['attachments'][0]['params']['attachedNotebookId']
return {
'notebookID': notebook_id
}
This will create a variable called ${notebookID} which is the name of the attached notebook. You can use it in the subject or body of the email like I described in my previous post.
Note that this method will only work if you have a single notebook attached. If you have multiple notebooks attached, there's no way to differentiate between them using this method.
Also, the name of the attachment will always be notebook.html. There's no way to change that unfortunately. Sorry for the inconvenience.
Thanks,
Zach
Hey @ZachM,
CAn you please direct me towards any documentation where I can find the details on the arguments being passed in this get_variables function.
I am trying to create a custom variable based on the already available variable-> $dssURL
Hi @Surbhi2512,
CAn you please direct me towards any documentation where I can find the details on the arguments being passed in this get_variables function.
I'm using the following custom-variable code in order to see what the arguments look like:
# compute your additional variables from the list of report items
# and return them as a dictionary.
def get_variables(items_json, scenario_run_json, step_run_output_json):
return {
"items": items_json,
"scenario_run": scenario_run_json,
"step_run_output": step_run_output_json
}
You can then use the following template to send the arguments via a mail reporter:
items: ${items}
scenario_run: ${scenario_run}
step_run_output: ${step_run_output}
I am trying to create a custom variable based on the already available variable-> $dssURL
The already-available variables aren't accessible by default, but you can make them accessible by assigning them to a scenario variable:
import json
# compute your additional variables from the list of report items
# and return them as a dictionary.
def get_variables(items_json, scenario_run_json, step_run_output_json):
scenario_run = json.loads(scenario_run_json)
custom_variable = scenario_run["variables"]["custom_variable"]
# Make changes to your custom variable here if needed
return {
"custom_variable": custom_variable
}
Thanks,
Zach