T#8 Attach Documents to CRM via flow

Do you need to get a file from an FTP / SFTP / OneDrive and attach it to a CRM record?

If YES, here we go!


In the below post we will explore establishing a connexion with the SFTP. (Connecting to the FTP or OneDrive will be very similar.) Then we are attaching the files named under the following format: fullname.csv to the corresponding contact by matching the fullname.



1. Connect to your Flow:

Navigate to https://emea.flow.microsoft.com

Click on "+ New" then choose "+ Automated - from blank".



2. Add your FTP / SFTP / One Drive trigger:

Search for "SFTP" and choose: "When a file is added or modified".


3. Configure your SFTP connexion by filling the required fields.


4. Get or Create the CRM record you are trying to add the attachment to.

In the example below we will fetch for the contact record and attach the file to it.

Here is what you need to include in the function shown next to the eq:

split(base64ToString(triggerOutputs()['headers']['x-ms-file-name-encoded']),'.')[0]


In fact, we are using 3 functions:


a) The split function:

split(text,seperator) will return an array of text by splitting over the chosen seperator.

For example: split('myfile.csv','.') will return an array with 2 components: split[0] = myfile and split [1] = csv

In our case we need the "myfile" text.

split( base64ToString(triggerOutputs()['headers']['x-ms-file-name-encoded']) ,'.')[0]


b) The base64ToString function:

base64ToString(text) will convert the base64 encoded field to a readable text version of the file name that we need.

split(base64ToString(triggerOutputs()['headers']['x-ms-file-name-encoded']),'.')[0]


c) The file name dynamic field:

The field code is automatically generated by picking up the field through the dynamic fields section.

split(base64ToString(triggerOutputs()['headers']['x-ms-file-name-encoded']),'.')[0]


5. Create the Note record (annotation)

Add the Common Data Services "Create" component:


Click on "Afficher les options avancées" and fill the fields as shown below:


Note that it is very important to convert the body of the file to base64 in order for the attached file not the be corrupted.


Once you save and test your flow, your file will be uploaded an attached correctly to the Contact record. (through the annotation)

0 views
Never Miss a Post. Subscribe Now!

© 2019 by Joseph Merhej 

  • Grey Instagram Icon
This site was designed with the
.com
website builder. Create your website today.
Start Now