apietrocini wrote: ↑Wed Mar 13, 2019 9:31 pm
Ok... This may be a dumb question, but is there a way to attach a complete dataset to one private data key...?
No dumb questions here. I haven't used Switch in a little while but here's my take on this.
The private data methods (setPrivateData, getPrivateData) allow you to set and get strings (
https://www.enfocus.com/manuals/Develop ... class.html). They usually aren't used to access sets of data -- more often for simple key/value pairs (example of two private data keys: MyJobNumber => "123456", MyCustomer => "Acme Corp"). But in that example, we have two related pieces of data saved as two keys (MyJobNumber and MyCustomer), so one might say that is a "data set". In fact, the "multiple result value" option of the script I gave you encodes a result of data into many PD keys (e.g. row1, row2, row3).
But a string is a string, so you could encode some form of dataset as a string, set it, then get it again. For example, let's say you had the JSON object:
Code: Select all
{
"this": "that",
"these": "those"
}
You could certainly set some private data with that encoded as a string (e.g. MyObject => '{"this":"that", "these": "'those"}'). But now you need to use scripting to parse out the contents again -- which could work fine for your use case. But, your Switch users will see confusing encoded strings within that single PD key -- which could be a problem. So yes, you can but its hard to deal with.
But Switch's first-class handling of Datasets is better suited for this job -- if you can get past the fact that they are a little harder to use (harder then setting private data anyways). You can do it a few ways -- but the most straightforward is to create an XML structure of your document and use that.
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<this>that</this>
<these>those</these>
Like private data, you retrieve the data with a key (e.g. MyDataset) but now you don't have to worry about decoding/parsing out bits of data like you would previously. You can navigate through the data in Switch with an expression like this:
Code: Select all
[Metadata.Text:Path="/[tag='this']/value",Dataset="MyDataset",Model="XML"]
Personally, I relied on (some would say abused) private data in most of my scripts. For a small number of data items, it was always very easy for users to select a few keys and for me to write those into private data. But if you have a large document then the Dataset is the way to go.