Client Libraries
# Client Libraries
# Introduction
We've came to situation where we've implemented same code logic in multiple codes and projects. So we created Client Libraries npm package in order to centralize repeated code logic in one place.
If you want to use Client Libraries in your project, copy and run this command:
npm i @talxis/client-libraries
# File Attribute
File Attribute class is designed to handle upload and download of the files from CDS. There are multiple was to do it and that is why we have mutiple sets of interfaces to handle each scenario. File attribute allows you to upload and download file both from our talxis_file entity and from your entity's custom file field.
# File
Regardless of approach, you will need to provide file information via IFileContent interface.
# IFileContent
Name | Type | Description |
---|---|---|
name | string | Name of the file. |
base64 | string | Base64 of the file content. |
path (optional) | string | File path. |
# File Upload
# TALXIS Files (default)
If you want to upload file to TALXIS File solution, you'll need to provide file information and (optionally) provide record ID where you want to save the file. If you don't provide record ID, new talxis_file record will be created and you will be provided file record ID.
# ITalxisFileConnection
Name | Type | Description |
---|---|---|
recordId | string | Record ID where file will be saved. |
# Custom File Location
If you want to upload file to your custom entity record, you'll need to provide file information and connection information where you want to save the file.
In this approach there are two connection interfaces:
# 1. IExecutionContextConnection
Name | Type | Description |
---|---|---|
executionContext | Xrm.Events.EventContext or Xrm.FormContext | Form's context. |
fileAttribute | string | Name of the file attribute where file will be saved. |
# 2. IFileAttributeConnection
Name | Type | Description |
---|---|---|
fileAttribute | string | Name of the file attribute where file will be saved. |
entityName | string | Name of the entity where file will be saved. |
recordId | string | Record ID of record where file will be saved. |
# Syntax
fileAttribute.uploadFileToAttribute(file, connection)
# Return value
On Success it will return record ID and Entity Type Name in manner of Xrm.CreateResponse interface.
Name | Type | Description |
---|---|---|
id | string | Record ID where file is stored. |
entityType | string | Name of the entity which is containing uploaded file |
# Example
import { ITalxisFileConnection, FileAttribute, IFileContent } from '@talxis/client-libraries';
let fileAttribute: FileAttribute = new FileAttribute();
const file: IFileContent = {
name: 'fileName',
base64: fileBase64,
path: 'TEST/PATH'
}
const connection: ITalxisFileConnection = {
recordId: '00000000-0000-0000-0000-000000000000'
}
const result = await fileAttribute.uploadFileToAttribute(file, connection);
if(result){
console.log("Record ID: ",result.id);
console.log("Entity Type:", result.entityType);
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File Download
# TALXIS Files (default)
If you want to download file from TALXIS File solution, you'll just need to provide record ID from where you want to get the file.
# ITalxisFileConnection
Name | Type | Description |
---|---|---|
recordId | string | Record ID where file is located. |
# Custom File Location
f you want to download file to your custom entity record, you'll need to provide connection information in same manner as uploading file.
There are two connection interfaces:
# 1. IExecutionContextConnection
Name | Type | Description |
---|---|---|
executionContext | Xrm.Events.EventContext or Xrm.FormContext | Form's context. |
fileAttribute | string | Name of the file attribute where file will be saved. |
# 2. IFileAttributeConnection
Name | Type | Description |
---|---|---|
fileAttribute | string | Name of the file attribute where file will be saved. |
entityName | string | Name of the entity where file will be saved. |
recordId | string | Record ID of record where file will be saved. |
# Syntax
fileAttribute.DownloadFileFromAttribute(connection)
# Return value
On Success it will automatically download file in browser.
# Example
import { ITalxisFileConnection, FileAttribute } from '@talxis/client-libraries';
let fileAttribute: FileAttribute = new FileAttribute();
const connection: ITalxisFileConnection = {
recordId: '00000000-0000-0000-0000-000000000000'
}
const result = await fileAttribute.DownloadFileFromAttribute(connection);
2
3
4
5
6
7