attach Dynamic file in folder in scenario

gikeylian
gikeylian Registered Posts: 4

Hello everyone,

After the creation of a scenario there is an option of adding Reporter to it,

i tried creating a reporter as mail and add the file that the scenario create
(scenario runs weekly and name the file based on the date).

I want to attach the file within the folder with all the other files present, in the mail reporter i am able to see the folder but dont know how i would proceed to put a "dynamic name" or latest file option.

Can anybody help me with this?

Best regards

Best Answer

  • LouisDHulst
    LouisDHulst Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Neuron, Registered, Neuron 2023 Posts: 54 Neuron
    edited July 17 Answer ✓

    Hi @gikeylian
    ,

    If I understand your Flow structure correctly you have some processing steps leading to a Folder that contains several files, and want to be able to pick the latest file added in the folder and send that via the Mail reporter?

    As far as I know Dataiku doesn't offer a way to do that through the visual interface, but you can change the settings of a reporter via the Python API.

    client = dataiku.api_client()
    project = client.get_default_project()
    scenario = project.get_scenario('YOUR_SCENARIO')
    settings = scenario.get_settings()
    json = settings.raw_reporters #returns reference to the settings

    #Change the settings to change the filepath used by reporter
    json[0]['messaging']['configuration']['attachments'][0]['params']['attachedItemPath'] = 'new_filepath'
    #Save
    settings.save()

    So you would add a Python script step in your Scenario, then use this code to change the settings of the reporter.

    Getting the correct filepath will depend on how you name your files. If the name increases sequentially you can just take the current filepath and modify it, so if the filepath is 'YYYYMMDD.csv' you could extract the date component, add a day using datetime.timedelta and then convert the date back to string.

Setup Info
    Tags
      Help me…