How to create a dataset

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

How to create a dataset

Post by apietrocini » Wed Mar 13, 2019 6:10 pm

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: 635
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Re: How to create a dataset

Post by gabrielp » Wed Mar 13, 2019 6:23 pm

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

If I've helped you and you'd like to say thanks, consider adding me on LinkedIn and leaving me an endorsement or recommendation. It helps a lot!

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

Re: How to create a dataset

Post by apietrocini » Wed Mar 13, 2019 6:52 pm

Thank you!

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

Re: How to create a dataset

Post by apietrocini » 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...?

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

Re: How to create a dataset

Post by gabrielp » Thu Mar 14, 2019 12:40 am

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

If I've helped you and you'd like to say thanks, consider adding me on LinkedIn and leaving me an endorsement or recommendation. It helps a lot!

jan_suhr
Advanced member
Posts: 220
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: How to create a dataset

Post by jan_suhr » Thu Mar 14, 2019 9:30 am

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: 22
Joined: Fri Mar 24, 2017 7:06 pm
Location: Cleveland, OH

Re: How to create a dataset

Post by apietrocini » Fri Mar 22, 2019 11:20 pm

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 » Sat Mar 23, 2019 10:23 am

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 » Thu Mar 28, 2019 10:36 am

Thanks for sharing information.

tocnaza
Newbie
Posts: 1
Joined: Mon Apr 08, 2019 7:25 pm

Re: How to create a dataset

Post by tocnaza » Mon Apr 08, 2019 7:26 pm

Thank you! I got it to work!

Post Reply