Uploading file to an existing Dataset

0
Hello,   Is it possible to upload a file from Mendix app to an existing Dataset on Teamcenter? Currently the only thing that is supported is Upload File java action which always creates a new Dataset.
asked
1 answers
0

Not sure if this will work but maybe something like this implemented in a java action could perform the desired action:

private static void attachFileToDataset(DataManagementService dmService, Dataset dataset, String filePath) throws NotLoadedException {
        File file = new File(filePath);

        if (!file.exists()) {
            throw new IllegalArgumentException("File does not exist: " + filePath);
        }

        try {
            DataManagement.CreateOrUpdateAttachmentsInput attachmentInput = new DataManagement.CreateOrUpdateAttachmentsInput();
            attachmentInput.clientId = "clientId_" + System.currentTimeMillis();
            attachmentInput.dataset = dataset;
            attachmentInput.filePath = file.getAbsolutePath();
            attachmentInput.namedReferenceName = "TEXT"; // Adjust according to dataset type

            CreateOrUpdateAttachmentsResponse response = dmService.createOrUpdateAttachments(new DataManagement.CreateOrUpdateAttachmentsInput[]{attachmentInput});
            if (response.serviceData.sizeOfPartialErrors() > 0) {
                throw new RuntimeException("Error attaching file to dataset: " + response.serviceData.getPartialError(0).getMessages()[0]);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

 

answered