Hi.
My goal is to have a button that takes pre-defined properties from an active object in a object table and export is as a .docx. I’ve tried with .xslx, .csv, .pdf and notepad template but it doesn’t solve my problem in the way I want.
Does anyone have any ideas for how I can solve this problem backend? I don’t want the user to have run a script locally that converts .json or other to .docx. I want it to be done on a push of a button directly in Foundry.
Best regards
You can create the docx in a function and save it as an attachment on your object. The user will be able to download this attachment.
I know there is sometimes friction with specific libraries (because of dependencies) in typescript, so I would rather try with a Python function on Object.
https://www.palantir.com/docs/foundry/functions/python-attachments/
From docs, example with a text file:
@functions(edits=[Aircraft])
def update_maintenance_log(
aircraft: Aircraft,
completed_maintenance_log: Attachment
) -> list[OntologyEdit]:
ontology_edits = FoundryClient().ontology.edits()
maintenance_log_data: BytesIO = aircraft.maintenance_log.read()
completed_maintenance_log_data: BytesIO = completed_maintenance_log.read()
# Compare the current aircraft logs and completed logs and create a new maintenance log
updated_maintenance_log_data: BytesIO = get_updated_maintenance_log(
maintenance_log_data,
completed_maintenance_log_data
)
editable_aircraft = ontology_edits.objects.Aircraft.edit(aircraft)
with open("updated-maintenance-log.txt", "wb") as f:
f.write(updated_maintenance_log_data.getbuffer())
editable_aircraft.maintenance_log = client.ontology.attachments.upload(
"updated-maintenance-log.txt",
"my_attachment"
)
return ontology_edits.get_edits()