Interface AttachedDocumentInfoInterface

The AttachedDocumentInfoInterface interface is used to store properties about any attached document linked to a part instance.

The AttachedDocumentInfoInterface is retrieved when using a InstanceMetadataInterface.getAttachedDocumentInfos i.e. when the metadata attached to a part instance are retrieved. The actual data (binary or not) will be retrieved by using the DocumentContentGetterInterface.

NB : Any attached document with a URL will NOT be retrieved, as the developer should know how to handle URLs.

The following code snippet allows a browser user to "download" the content of an AttachedDocumentInfoInterface by the DocumentContentGetterInterface. Such a code may be triggered while receiving the DocumentContentGetterInterfaceSignal.DocumentContentReady of the DocumentContentGetterInterface.

/** 
* Sample to illustrate how to trigger a file dialog to save the content of an attached document.
*/
import { AttachedDocumentInfoInterface, DocumentContentGetterInterface } from 'generated_files/documentation/appinfiniteapi';

let getDocumentData : (pDocumentContentGetterInterface : DocumentContentGetterInterface) => boolean = undefined;

// pDocumentContentGetterInterface.retrieveDocumentContent(lAttachedDocumentInfo) has been called previously

getDocumentData = (pDocumentContentGetterInterface : DocumentContentGetterInterface) : boolean =>
{
// do nothing in case of error
if (pDocumentContentGetterInterface.getLastError() !== undefined)
{
return false;
}
const lAttachedDocumentInfo: AttachedDocumentInfoInterface | undefined = pDocumentContentGetterInterface.getAttachedDocumentInfo();
// document is set ?
if (!lAttachedDocumentInfo) {
return false;
}
const lDocumentContent: string | Uint8Array | undefined = pDocumentContentGetterInterface.getDocumentContent();
// document is ready ?
if (!lDocumentContent) {
return false;
}
// create a <a> markup for download
const downloadLink = document.createElement('a');
downloadLink.target = '_blank';
let lExtension: string;
switch (lAttachedDocumentInfo.documentMimeType) {
case 'application/json': lExtension = 'json'; break;
case 'application/xml': lExtension = 'xml'; break;
case 'application/x-qt-richtext': lExtension = 'html'; break;
case 'image/jpg': lExtension = 'jpg'; break;
case 'image/jpeg': lExtension = 'jpeg'; break;
case 'image/png': lExtension = 'png'; break;
case 'text/csv': lExtension = 'csv'; break;
case 'text/html': lExtension = 'html'; break;
case 'text/plain': lExtension = 'txt'; break;
case 'text/xml': lExtension = 'xml'; break;
// do nothing in case of "unknown" mime type
default: return false;
}
// nice default file name for download
downloadLink.download = lAttachedDocumentInfo.documentName + '.' + lExtension;
// convert downloaded data to a Blob
const blob = new Blob([(typeof lDocumentContent === 'string') ? lDocumentContent : <BlobPart> lDocumentContent.buffer], { type: lAttachedDocumentInfo.documentMimeType });
// create an object URL from the Blob
const URL = window.URL;
const downloadUrl = URL.createObjectURL(blob);
// set object URL as the anchors href
downloadLink.href = downloadUrl;
// append the anchor to document body
document.body.appendChild(downloadLink);
// fire a click event on the anchor
downloadLink.click();
// cleanup: remove element and revoke object URL
downloadLink.remove();
URL.revokeObjectURL(downloadUrl);
return true;
};

// lDocumentContentGetterInterface has been created previously and
// retrieveDocumentContent has been called
let lDocumentContentGetterInterface : DocumentContentGetterInterface;

getDocumentData(lDocumentContentGetterInterface);

Please refer to the DocumentContentGetterInterface for more information.
Data Retrievers

interface AttachedDocumentInfoInterface {
    documentDescription: string;
    documentId: string;
    documentMimeType: string;
    documentName: string;
    documentSecurityTags: string[];
    documentUrl: string;
}

Properties

documentDescription: string

The description relative to the attached attached document content.

documentId: string

The id of the attached document.

documentMimeType: string

The mime type of the attached document.

Available types are (not comprehensive):

  • application/json.
  • application/xml.
  • application/x-qt-richtext.
  • image/jpg.
  • image/jpeg.
  • image/png.
  • text/csv.
  • text/html.
  • text/plain.
  • text/xml.

Depending on your DMU provider, more or less types may be available.

documentName: string

The name of the attached document.

documentSecurityTags: string[]

The security tags of the document.

documentUrl: string

The url of the attached document. If empty, then the attached document has no URL.

Any attached document with a URL will NOT be retrieved.