Skip to content

Use Cases

Thomas Theunen edited this page Nov 7, 2021 · 14 revisions

Use Cases

Below you will find some use-cases to why I created this CLI tool.

The below scenarios assume you have set up your connection with your environment.

Backing up your metadata

When creating and updating Custom Attributes on your Objects, you want to make sure that you have a backup if someone ever deletes or modifies its properties.

Click here for detailed steps and commands of this scenario.

The first step is easy! In the root folder of your project, execute the following command:

sfccdx attribute:get

What happened? I don't pass any options to this command? Why yes! If you run it like this, it will download the Custom Attributes of all the System Objects in your environment!

Once the command has finished, you should be able to find all information regarding your objects in the following folder:

<project-folder>/data/meta/system-objecttype-extensions/

Attributes downloaded

How would I put this information back on my environment (e.g., someone accidentally deleted something)? Simple, you just run this command:

sfccdx attribute:push -o <object> -a <attribute>

The result should be something like this:

Push Result

Info: For now, it is not possible to push an entire object back in one go. (Will change in the future)

Creating new attributes

Are you tired of creating a batch of attributes in the Business Manager? Want to copy-paste another attribute as a template and change the ID? Then we have the commands you need!

Click here for detailed steps and commands of this scenario.
First, let's fetch all System attributes available on the object so we can easily copy-paste! We can do this by adding the option -isa ( --include-system-attributes ) to your get command.

sfccdx attribute:get -o <object> -isa

SFCCDX will fetch all of our attributes, including the ones present by default. You should see something like this.

UUID example

Now that we have our example, let's copy the file <attribute>.json to the one we want in the same folder. For instance, customUUID.json.

Don't forget to change the id attribute within the JSON and all other attributes like Display Name.

Now that the file is ready, execute the following command:

sfccdx attribute:push -o <object> -a customUUID

Create custom attribute

All done! Your attribute should now be available on the instance.

Change a Custom Attribute Type

It doesn't happen often, but sometimes you made an attribute a String, but afterward thought it was better as a Double. It's an easy fix, right? Well... yes and no.

Click here for detailed steps and commands of this scenario.
Changing an attribute type is never easy:
  • It is removed from the attribute group
  • All its values on records are cleared

There are some safeguards on the OCAPI for this, but you can re-create it with just one extra option to the push command.

sfccdx attribute:push -o <object> -a customUUID -f

Using -f ( --force-recreate ), it is deleted and created again. This also happens in the Business Manager; you don't "see" it when you do it manually. This is also the reason why it disappears from Attribute Groups, and all values are cleared.

Managing Attribute Groups

Besides managing your attributes in the Business Manager, assigning multiple attributes to a group (and keeping track of them) can be a hassle. Not to worry, you can quickly push and pull these!

Click here for detailed steps and commands of this scenario.

First of all, let us get those pesky Attribute Groups from the environment!

sfccdx attributegroup:get -o <object>

This command will download all existing Attribute Groups (including the system ones) to the local file system in JSON files. It should look something like this:

Attribute Group Fetched

Two files should have appeared:

  • A file containing the JSON describing the group and its details
  • A file containing a list of all attributes assigned to that Attribute Group (A JSON array)

To assign more attributes to a group, add them to the file containing the list of assignments and push it back to the environment like this:

sfccdx attributegroup:push -o <object> -g <attributegroup>

This should result in this in the terminal:

Updated Attribute Group

The OCAPI only allows assigning attributes per attribute, so if you have an extensive list of attributes, you will see a message for each of them separately. I will look into using the Batch API later to resolve this.