How to create a dataset

Post Reply
apietrocini
Member
Posts: 32
Joined: Fri Mar 24, 2017 7:06 pm
Location: Cleveland, OH

How to create a dataset

Post by apietrocini »

Can someone put on the right path... I'm trying to create a script that will build or create a dataset... This is what I "think" needs done, just not sure on the proper execution...

function jobArrived( s: Switch, job: job )

var theDatasetName = s.getPropertyValue("DataSetName");
var theKey = s.getPropertyValue("Key");
var theValue = s.getPropertyValue("Value");

I would guess that I need to map the key and value to the dataset, just not clear on the proper way to do that...

Thanks in advance,

Anthony
User avatar
gabrielp
Advanced member
Posts: 645
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Re: How to create a dataset

Post by gabrielp »

For simple key value pairs its much easier to write to private data -- but here is an example of writing to a dataset:
- https://github.com/open-automation/swit ... #L324-L367
Free Switch scripts: open-automation @ GitHub
Free Switch apps: open-automation @ Enfocus appstore

Want to hire me? I'm looking for my next gig. Contact me on LinkedIn or via email.
apietrocini
Member
Posts: 32
Joined: Fri Mar 24, 2017 7:06 pm
Location: Cleveland, OH

Re: How to create a dataset

Post by apietrocini »

Thank you!
apietrocini
Member
Posts: 32
Joined: Fri Mar 24, 2017 7:06 pm
Location: Cleveland, OH

Re: How to create a dataset

Post by apietrocini »

Ok... This may be a dumb question, but is there a way to attach a complete dataset to one private data key...?
User avatar
gabrielp
Advanced member
Posts: 645
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Re: How to create a dataset

Post by gabrielp »

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.
Free Switch scripts: open-automation @ GitHub
Free Switch apps: open-automation @ Enfocus appstore

Want to hire me? I'm looking for my next gig. Contact me on LinkedIn or via email.
jan_suhr
Advanced member
Posts: 586
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: How to create a dataset

Post by jan_suhr »

There is an app for that :-)

With the App "Make XML" you can create your own dataset form variables in Switch or write your own values.

The App can save this as an XML file or as a Dataset.

https://www.enfocus.com/en/appstore/product/make-xml
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
apietrocini
Member
Posts: 32
Joined: Fri Mar 24, 2017 7:06 pm
Location: Cleveland, OH

Re: How to create a dataset

Post by apietrocini »

Thank you!!! I got it to work!
risha
Newbie
Posts: 2
Joined: Mon Mar 18, 2019 9:45 am

Re: How to create a dataset

Post by risha »

Thanks for sharing great information on data set, keep sharing.
Nayna
Newbie
Posts: 1
Joined: Thu Mar 28, 2019 10:34 am

Re: How to create a dataset

Post by Nayna »

Thanks for sharing information.
Post Reply