Uploading datasets via CLI

A while back I wrote a blog on how to export datasets from Tableau CRM (Einstein Analytics) using Salesforce CLI and a plugin from Mohan Chinnappan. It seems Mohan’s plugin was well received and he has since expanded on it to upload csv files to Tableau CRM. This is powerful if you want to update your datasets programmatically, so let’s have a look

Getting the plugin

Needless to say to use the plugin you need to install the plugin. As I explained the process in the export blog I would encourage you to follow the steps laid out there.

Note: You need to both install the Salesforce CLI and Mohan’s plugin to continue to benefit from this blog. Check out the steps in Export your Einstein Analytics datasets.

If you already have the plugin you may very well need to update it to get the latest version. For my demonstration in this blog I am using Apple’s terminal.

In Terminal we want to run the following command to update all the plugins.

sfdx plugins:update

Once this is done you can check the version of the installed plugins by using the following command:

sfdx plugins

As you can see the version I am using for this blog is 0.0.69, however you may discover more updates have been made available and you have a later version.

Note: Check out the latest enhancements in Github.

The load commands

Alright let’s look at the load command that we will be using; to see the updated full list of options for this command you can always run the help command.

sfdx mohanc:ea:dataset:load -h

Let’s have a look at the common options for this command.

Username

Use the -u option to specify a username to use for your command.

--The option
sfdx mohanc:ea:dataset:load -u <insert username>

--Example
sfdx mohanc:ea:dataset:load -u rikke@demo.org

Datafile

Use the -d option to specify the csv file and it’s location to import.

--The option
sfdx mohanc:ea:dataset:load -u <insert username> -d <insert datafile.csv>

--Example
sfdx mohanc:ea:dataset:load -u rikke@demo.org -d Desktop/File.csv

Operation

Use the -o option to specify what type of operation (Overwrite, Append, Upset or Delete) you want to leverage. If you leave this option out the default behavior is to conduct an overwrite.

--The option
sfdx mohanc:ea:dataset:load -u <insert username> -d <insert datafile.csv> -o <insert operation>

--Example
sfdx mohanc:ea:dataset:load -u rikke@demo.org -d Desktop/File.csv -o Overwrite

Datafile format

As the aim is to import a csv file to Tableau CRM there are some considerations to the format of your fields. Below you will see the expected format for date and DateTime fields.

Note: Multivalue fields can also be imported, but you need to specify which fields are multivalue and determine the separator used.

Upload csv file as a dataset

Before getting to the actual steps let’s quickly review the file I will be using. It’s a simple test file with only three rows, but it will contain different field types.

Note: Before using the load command you would have to log in to the desired org by using the command sfdx force:auth:web:login, which will launch the login window in a browser.

With that out of the way let’s have a look at how to construct our command to import the csv file.

Step 1 – use the load command from the plugin

sfdx mohanc:ea:dataset:load

Step 2 – define the username to use by adding the -u option

sfdx mohanc:ea:dataset:load -u rikke@discovery.gs0

Step 3 – define what csv file and it’s location to use by adding the -d option

sfdx mohanc:ea:dataset:load -u rikke@discovery.gs0 -d Desktop/CityEA.csv

Step 4 – define the operation you want to perform by adding the -o option

sfdx mohanc:ea:dataset:load -u rikke@discovery.gs0 -d Desktop/CityEA.csv -o Append

Step 5 – as I have a multi value field ‘Multi’ I need to specify that it should be treated as a multi value field by using the -m option.

sfdx mohanc:ea:dataset:load -u rikke@discovery.gs0 -d Desktop/CityEA.csv -o Append -m Multi

Step 6 – the default multi value separator used is a comma, however you can also specify it by using the -s option.

sfdx mohanc:ea:dataset:load -u rikke@discovery.gs0 -d Desktop/CityEA.csv -o Append -m Multi -s ,

Step 7 – I have a postcode field that looks to be numeric, but I want it to be interpreted as a text field. To make this specification I can use the -f option followed by the name of the numeric field you want to be a text value.

sfdx mohanc:ea:dataset:load -u rikke@discovery.gs0 -d Desktop/CityEA.csv -o Append -m Multi -s , -f Postcode

And that is it. Press enter.

Once you get “done” in your command window, it’s set to queue in the Data Manager and you can go there to see when the operation has completed and the dataset is updated.

If you explore the dataset you will notice that the postcode containing numeric values is considered a dimension that you can group by.

Hope you see some great potential of the export and load function of this plugin.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.