What if you want to create a relatively complex text file in Switch? Say… something like an XML file, or a JDF, or a complex JSON file. Yes, you can write a custom script for this, but even with a script, doing this is still very messy and a lot of hard and painstaking work. If only there would be a way to make that easier…
Wait a minute, when you’re generating HTML files for a web site, isn’t that very much the same problem? How do those systems deal with that? Turns out that smart people invented something called a templating engine. You provide a template and can then insert variables in that template in a structured way. Modern templating engines even allow you to create loops, insert conditionals and so on.
This Switch app uses a templating engine – Embedded JavaScript templating, or EJS – to do exactly this. The app has different ways to specify where the template is and to specify input variables for the template. It builds the output from the template injected with these variables and then outputs it according to what you need in the rest of the workflow.
The sky is the limit! :) However, some practical examples would be:
Of course you can write a custom script for this (well, if you have access to the scripting module that is). But scripts to write complex text files very quickly become messy. Using this app has the advantage that you separate the business logic from the presentation. Use a script to attach information to a job, or to generate a custom JSON file. Then use this app and a custom template to format your information into the output format you want. Doing things this way both your script and the template become simpler and are more easily maintainable.
I found this program when I need to create an order confirmation based on JSON from an MIS system. And it fit perfectly into my workflow.
I just needed to learn a bit about EJS-templates.
A nice touch is that is also possible to use Switch Private Data in the templates.
This is one of the best free apps in the App store. We use it for all our flows to create csv-log files to be able to track the usage of our flows (and take actions for flows that are not beeing used for a long time). We also use it to make different lists for batch jobs etc. A tip if you are batch-running alot of files through the app, whick can cause writing errors, can be to space jobs 1 sec apart with the Hold job app.
This is a great app that makes it easy for me to generate jdf's on the fly, huge possibilities for a very easy to use app.