AppData companion

One of the new features in Tridion 2011 that has not gotten much public attention is the so-called application data (AppData for friends). The application data feature gives us a mechanism to store additional, application-specific data with every Tridion item. So if you have a Component in Tridion that corresponds to some file outside in the real world, you could store the path to the file in the Component's AppData. You can of course also store that information in a metadata field. But doing so exposes the information to every user that has access to the Component. The beauty (and curse) of AppData is that it is only available through the API. It is meant to be produced and consumed by an add-on application.

To make it a bit easier to see how AppData is already being used in a system and to allow me to manipulate AppData, I wrote a small command line program. As you may have guessed, the program is called AppData.exe.

The main download contains two files: AppData.exe and AppData.exe.config. AppData.exe connects to Tridion Content Manager through the Core Service. The location of the core service endpoint is specified in AppData.exe.config.

Usage examples

Display all appdata on folder tcm:6-19-2 and all items under that folder.

C:\>appdata view tcm:6-19-2
tcm:6-321.ome:TrackedPublicationList=<The value is not an ASCII string. Save it to a file using AppData export ...>

So there is only one appdata value, called ome:TrackedPublicationList, on component tcm:6-321 (which is under folder tcm:6-19-2). From the name it seems that this value is used by Online Marketing Explorer to keep a list of the publications it tracks. Note how it uses an ome: prefix to somewhat namespace application data values. This will come in handy later.
The value of the ome appdata is non-ASCII. We'll cover how to deal with that later.

Let's add a custom appdata value called Test to the folder.

C:\>appdata set tcm:6-19-2 Test "Hello world"
tcm:6-19-2.Test=Hello world 
C:\>AppData view tcm:6-19-2
tcm:6-19-2.Test=Hello world
tcm:6-321.ome:TrackedPublicationList=<The value is not an ASCII string. Save it to a file using AppData export ...>

So now we have two appdata values, the original ome value on component tcm:6-321 and the Test value we just set on folder tcm:6-33-2.

We can also just view appdata with a specific name

C:\>appdata view tcm:6-19-2 Test
tcm:6-19-2.Test=Hello world

The name is a regular expression match, so the value above would also match Testing, Test:me, Tester, etc.
Remember: the search is recursive, so it is quite easy to find all values that are related to your application if you just follow a naming convention (like ome seems to do).

C:\>appdata view tcm:6-19-2 ome
tcm:6-321.ome:TrackedPublicationList=<The value is not an ASCII string. Save it to a file using AppData export ...> 
C:\>appdata delete tcm:6-19-2 Test
Deleted tcm:6-19-2.Test 
C:\>appdata view tcm:6-19-2 Test

So deleting a value is easy too. Be careful though: deletion is recursive, just like viewing. So be sure to set a specific enough application id and always do a view before you delete.

You can also set empty values

C:\>appdata set tcm:6-19-2 Test
tcm:6-19-2.Test= 
C:\>appdata view tcm:6-19-2 Test
tcm:6-19-2.Test= 
C:\>appdata delete tcm:6-19-2 Test
Deleted tcm:6-19-2.Test

Empty values may be useful to simply mark a certain item as belonging to your application.

Now let's see how we can handle non-ASCII values, like the ome:TrackedPublicationList above

C:\>appdata download tcm:6-321 ome:TrackedPublicationList ome.xml
tcm:6-321.ome:TrackedPublicationList written to ome.xml

We downloaded the value of ome:TrackedPublicationList on tcm:6-321 into a file called ome.xml. Let's see what's inside it:

C:\>type ome.xml
ĩ�<?xml version="1.0" encoding="utf-8"?><TrackedPublications xmlns="http://www.tridion.com/OnlineMarketingExplorer/1.0" />

So the value is XML. But there's some weird characters in front of the XML (for those into that type of thing: it's a byte-order-marker), which means that AppData.exe can't read it since it only handles ASCII values. Feel free to change the program to handle Unicode, but we'll keep moving for now... Let's first clear up our mess.

C:\>del ome.xml

And then see if we can add a custom binary to our folder

C:\>appdata upload tcm:6-19-2 PreviewImage IMG_1086.JPEG
tcm:6-19-2.PreviewImage read from IMG_1086.JPEG 
C:\>appdata view tcm:6-19-2
tcm:6-19-2.PreviewImage=<The value is not an ASCII string. Save it to a file using AppData export ...>
tcm:6-321.ome:TrackedPublicationList=<The value is not an ASCII string. Save it to a file using AppData export ...> 
C:\>appdata download tcm:6-19-2 PreviewImage preview.jpg
tcm:6-19-2.PreviewImage written to preview.jpg

So we uploaded a JPEG into an appdata value and then downloaded it again into a different file. This all seems to work fine.

All that's left is for us to clean up our system.

C:\>appdata delete tcm:6-19-2 PreviewImage
Deleted tcm:6-19-2.PreviewImage 
C:\>appdata view tcm:6-19-2
tcm:6-321.ome:TrackedPublicationList=<The value is not an ASCII string. Save it to a file using AppData export ...>

So with that we're back to where we started.


Developer
Company
License agreement
Download package
Tags
:    appdata,  application data,  cms,  2011
Version
:   1.0
Source
:   Yes

About the Author
Frank van Puffelen
Technical Director

Frank joined SDL in 2004 and as a principal developer worked on many of the company's releases until the end of 2012. He is now the technical director of ZyLAB USA.

ZyLAB

Most Popular Building Blocks

These are the most popular Building Blocks. Did you already get them?