Create File From Template V1 - Enfocus

1y ago
319.62 KB
11 Pages
Last View : 13d ago
Last Download : 4m ago
Upload by : Fiona Harless

Four Pees Switch AppCreate file fromtemplateFour Pees nvKleemburg 19050 GentbruggeBelgiump 32 9 237 10 00f 32 9 237 10 01info@fourpees.comwww.fourpees.comWritten by: David van Driessche, CTO Saved on: Friday 18 June 2021 Version: Version 1

Create file from template Four PeesTable of ContentsIntroduction . 31.1.Versions . 3How to use . a template result into the flow .4Using a dataset .4Writing to a fixed file . 5Template engine . variable replacement . 6Conditional processing . 6Outputting repeating information . 6Injected variables . 7Examples . 8Need help? . 8Properties . . 9Variables . 9Result . 9Tips, tricks & pitfalls . encoding . 10What does “text file” mean? . 10Separating logic and view . 10More information . Pees feel the good flow . 11Free apps. 11ã 2021, Four Pees nv app documentation Page 2 / 11

Create file from template Four PeesIntroductionWhat if you want to create a relatively complex text file in Switch? Say something like an XML file, or a JDF, or a complexJSON 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 hardand 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 thosesystems deal with that? Turns out that smart people invented something called a templating engine. You provide atemplate and can then insert variables in that template in a structured way. Modern templating engines even allow you tocreate loops, insert conditionals and so on.This Switch app uses a templating engine – Embedded JavaScript templating, or EJS – to do exactly this. The app hasdifferent ways to specify where the template is and to specify input variables for the template. It builds the output fromthe template injected with these variables and then outputs it according to what you need in the rest of the workflow.The rest of this document describes how to use the app and explains the different properties.1.1. VersionsThe following is a short version overview: version 1: initial version of the app.ã 2021, Four Pees nv app documentation Page 3 / 11

Create file from template Four PeesHow to useThis app is quite flexible in how it can be used in a Switch workflow. Of course, it’s goal in life is to create a text file basedon a template and variables, but it still allows quite a bit of flexibility in how it does that. This chapter shows three possibleway of using it so you can find some ideas. After that, it’s up to your own flexibility (and of course we can help with that!).2.1. Inserting a template result into the flowPerhaps the most straightforward way of using the app, is by inserting it into a workflow as shown here. In this example: A JSON file containing order information enters the workflow and hits the app. The app property that specifies wherethe variables are says “Incoming job”. The template is read from a fixed file using the template property of the app. And the result property is set to “Send to outgoing connection”.What is important of course is that the incoming JSON file stops at the app and is then discarded. The output of the app isthe text file with the email template and inserted variables.2.2. Using a datasetWhat if you want to just let your incoming job pass through the app? That can be done by using a dataset. In the aboveexample: It’s still a JSON file that enters the workflow and hits the app. So the variables property is again “Incoming job”. The template is also still a fixed file. But now the result property of the app is set to “Attach as dataset”.In this case, the output of the app is the original job – which is unaltered – except that it now has a new dataset attachedto it. If for example you’d want to send an email later in the flow, this could be ideal as the “Mail send” tool allows pickupup the mail content from a dataset.When you’re attaching the dataset, you can also specify what type of dataset it should be. The app supports XML and JDFdatasets; anything that is not one of these two formats should be set to “Opaque”.ã 2021, Four Pees nv app documentation Page 4 / 11

Create file from template Four Pees2.3. Writing to a fixed fileThe third example is again quite different, and it could for example be used to write log information into a CSV file. In thiscase, a regular job enters the flow and hits the app, and that job is also sent to the output folder of the app (in the screengrab, the “To next task” folder).But now the app writes the result of the template completion to a fixed file. The app lets you specify both the folder andthe file name for this file, so you could easily write a new file every day. And as the app lets you choose betweenoverwriting an existing file or appending to the end of it, both writing a one of file and adding to an existing log file iscompletely supported.If you download these example flows from the page on the Enfocus AppStore for this app, you’ll see that the CSVtemplate can even be created in such a way that you can write out a file with a header. The app provides additionalvariables so your template can know whether it’s the first time you write to this particular log (and then it can add theheader), or whether this will be appending (in which case it skips writing the header).ã 2021, Four Pees nv app documentation Page 5 / 11

Create file from template Four PeesTemplate engineA template engine is a text processing engine that ingests a template (a text file) and outputs a new text file. The templateoffers to capability to do text replacement, ranging from simple substitutions of a single variable, over conditionalprocessing to looping. While text replacement engines are mostly used for web development, and the creation of HTMLpages, they can easily be used for any text-based file format.This app uses the EJS template engine. Some usage examples are included below, but much more documentation can befound here: If you create the templates using Visual Studio Code, there are a number of Visual Studio Codeplug-ins to help you, ranging from syntax coloring to quickly creating the substitution codes you’ll need. Remark that EJSuses JavaScript as part of its template syntax, which makes it rather elegant to use. And no, for simple substitutions, youreally don’t need to speak JavaScript.3.1. Simple variable replacementThe simplest use case is to have a template with some variables, that are then replaced. This would allow you for exampleto write something like:My favorite animal is a %- favoriteAnimal % .If you feed this template variables, and among the variables there is one called favoriteAnimal, whatever the value ofthat variable is would be inserted into the output string.My favorite animal is a penguin.You could make the output into HTML by using HTML tags in your template around the text: h2 My favorite animal is a %- favoriteAnimal % . /h2 Or if you prefer your files in XML format: messages message My favorite animal is a %- favoriteAnimal % . /message /messages Remark that everything in your template will remain untouched, except for the EJS tags (which normally start with “ %”).And while these examples show HTML and XML, you can of course do the same in a MarkDown file, a CSV, a JSON 3.2. Conditional processingYou can use the incoming variables to “sometimes” output part of a template, again based on the variables you feed yourtemplate: % if (favoriteAnimal) { % My favorite animal is a %- favoriteAnimal % . % } else { % I don’t have a favorite animal. % } % The result of this template (given that there is a correctly named variable) will be a single line of text. Which of the twolines is output depends on the result of the “if” condition.3.3. Outputting repeating informationThe biggest challenge for a simple text creation app is information that repeats, and especially so if you don’t know aheadof time how much data there will be. With a template this can be handled quite nicely: % items.forEach(item { % Ordered product: Quantity: %-item.quantity-% , total price: %-item.price-% % }) % ã 2021, Four Pees nv app documentation Page 6 / 11

Create file from template Four PeesThe template snippet above assumes our variables include “items”. Using standard JavaScript, the template outputsinformation for each object in the items list.3.4. Injected variablesAny variables that you define in a JSON file or using the key / value mechanism in the app properties, will be available foruse in your template. For example, if your JSON looks as follows:{ name: “Pingo” }In your template you will be able to use the variable “name” and it will be replaced by its value. The app tries to make thisprocess a bit easier for you, by also injecting job and switch related information automatically, without you having to doanything.3.4.1. Standard variablesBy default, the app injects an object called "fourpees” into your variable set. Even if you would pass an empty JSON file orno key / value pairs, the “fourpees” object would still be available. In this object the following properties are defined: the unique ID for the job the full name of the job info.nameproper: the name of the job without extension info.extension: the extension of the job info.isfile: true if the job is a single file, false otherwise info.isfolder: true if the job is a job folder, false otherwise privatedata: an object containing a key for each private data field associated with the job and its value. app.appendingtoexistingfile: either true or false, see the “New file” section below.In the template, you can use this information just as you would use other variables you inject in your JSON object. Forexample: Is going to be replaced by the name of the job (including extension). Likewise: %-fourpees.privatedata.fpNumberOfPenguins-% Is going to be replaced with the private data field called “fpNumberOfPenguins” as defined for the incoming job.3.4.2. New file or appending?In some cases, you might want to have a different template output depending on whether this is the first time you’rewriting to the output file or you’re simply appending to an already existing file. A good example would be a CSV file withheaders. When creating the CSV file, you want to write both the headers and the incoming data row. When appending tothe existing CSV file, you only want to write the incoming data row.The “app.appendingtoexistingfile” variable is meant exactly for this. It will be set to “false” in all case, except whenthe properties of the app ask to append to a file (rather than overwriting it), and the file actually already exists. If you wantto use the app to write a log file for example, this could be done like this: % if ( false) { % // Write headers % } % // Write dataThe template can in this way do anything that needs to happen only when the output is freshly created.ã 2021, Four Pees nv app documentation Page 7 / 11

Create file from template Four Pees3.5. ExamplesOn the Enfocus AppStore you can download an archive with small examples of how to use this app in actual workflows.Go to the page for this app and look at the bottom (next to the link to the documentation file you’re reading now).3.6. Need help?For simple purposes templates are not that difficult to create. If your project is more complex, so might the correspondingtemplate be. Don’t hesitate to get in contact with us (using if you want to see whether we can helpyou to complete your project.ã 2021, Four Pees nv app documentation Page 8 / 11

Create file from template Four PeesPropertiesThe following properties can be used to change the behavior of the app.4.1. TemplateIn order to function, the app needs an EJS compatible template, which is specified using the “Template” property. Thefollowing possibilities are supported: Incoming job: the EJS template is the incoming job. In this case the option “Incoming job” cannot also be selected forthe “Variables” property (the incoming job can’t be both an EJS template and a JSON with variables). File: the EJS template is specified in an external file. In this case an additional option “File” allows specifying the locationof the template file on your system. Dataset: the EJS template is attached to the incoming job as a dataset. An additional “Dataset” property now allowssetting the name of the used dataset.4.2. Variables Incoming job: the variables are specified as a JSON file which is the incoming job. In this case the option “Incoming job”cannot also be selected for the “Template” property (the incoming job can’t be both an EJS template and a JSON withvariables). File: the variables are specified as a JSON file. In this case an additional option “File” allows specifying the location of theJSON file on your system. Dataset: the variables are specified as a JSON file which is attached to the incoming job as a dataset. An additional“Dataset” property now allows setting the name of the used dataset. Text: sometimes your variable needs are simple. In that case you can use this option. It allows you to specify anunlimited number of variables and their values in a simple key / value format. Select this option and use the additional“Text” property. It contains an example of how to specify the variables in the proper format. JSON as text: if simple key / value pairs don’t cut it, but your needs are still simple enough, you can also specify a JSONobject directly in the “JSON as text” property of the script. You can use Switch variables in your JSON definition ofcourse.4.3. ResultThis app injects the specified parameters into the template used. The result of this is a “blob” of text created by the EJStemplate engine. The “Result” properties decide how this result is going to be used. It supports the following values: Send to outgoing connection: the template result is written to a file, which is then sent to the outgoing connection ofthe script. The original job is discarded. When this is selected, additional properties appear:oFile name: the full name (including extension) of the output file Write to file: the template result is written to the specified file. If there is an outgoing connection, the original job is sentto that outgoing connection. If not, the original job is discarded. When this is selected, additional properties appear:oFolder: the folder to which to write the result file. This folder must exist.oFile name: the full name (including extension) of the output fileoMode: “Overwrite” if any file with the same name is going to be overwritten, or “Append” if the app willappend to an existing file (if it exists). Attach as dataset: the template result is attached as a new dataset to the original job, which is then sent to theoutgoing connection. When this is selected, additional properties appear:oDataset: the name of the dataset the result will be written to.oType: the type of the dataset you want to attach.ã 2021, Four Pees nv app documentation Page 9 / 11

Create file from template Four PeesTips, tricks & pitfallsThis chapter describes more advanced topics, limits and implementation limits, tips and tricks.5.1. Text encodingThe text file that is created always uses UTF-8 (Unicode) encoding. As the text you would input in Switch normally also willbe UTF-8, this shouldn’t pose any issues. But knowing the encoding of the created text file may be important todetermine how you’re going to handle this file further down in the Switch flow. You’ll have to make sure it’s interpreted asUnicode at that point as well.5.2. What does “text file” mean?In the context of this app, “text file” can be interpreted as any file that is written in a textual format (as opposed to abinary file). This means that this app could just as well be used to write a CSV file, JSON, XML, RTF or any other textencoded file. But the app has no built-in mechanism to make your life easier if you decide to write these files – you’ll haveto make sure you follow the proper rules.5.3. Separating logic and viewWhile reading about this app, you could consider that it might be much easier to simply write a custom script that outputsthe file content you need. This is not a wrong thought, but it really depends on what you are doing.Writing a custom script that outputs a complex XML or JDF for example quickly becomes very tedious, and a big part ofthat is because you mix the workflow logic and the view, or representation, of the data that you want. If you can have acustom script or workflow that generates a JSON object (which is easy in JavaScript) and then use this app to do theconversion of that JSON data to the actual XML or JDF file you want, that will simplify the logic in both places. Your scriptcan now focus on the logic, which will make it smaller and easier to maintain, and the template you create in this app canfocus on what exactly you want to output.The question is never, can I do this with a custom script. The real question is: “what is the easiest way to do this”. Now, andsix months from now when the customer (which may be you yourself) comes back with their feature requests.ã 2021, Four Pees nv app documentation Page 10 / 11

Create file from template Four PeesMore information6.1. Four Pees feel the good flowThis app was created by Four Pees. You can find more information about our company here: created this app based on the experience we have with projects where Switch is used, but of course that is not aguarantee that the app will be suitable for every project out there.If you run into a problem, or this app doesn’t completely cover what you had hoped it would, don’t hesitate to send usfeedback. There are multiple ways you can do this: Go to our website and use the contact page: Send us an email at You’ll get a confirmation message and we’ll be with you before you can say“Automation”.6.2. Free appsIf you’re using one of our free apps, please keep in mind that our support on those is limited. We believe this is fair as freeapps can’t be handled the same way as payable project work.That having been said, we of course will try to help you as best as we can! Just get in contact and we’ll have aconversation on how we can help you.ã 2021, Four Pees nv app documentation Page 11 / 11

Create file from template Four Pees Template engine A template engine is a text processing engine that ingests a template (a text file) and outputs a new text file. The template offers to capability to do text replacement, rangi

Related Documents:

The design file that is used does not matter since we are editing the template library .itl file. S.R. 185 Template From the Corridors tab, choose Template Create Template. The Create Templates dialog is opened with the template library for the WorkSet loaded o Create a new template

then select Word Template. Save it somewhere that you can find easily. 3. To modify your template later, open Word first, then open the template file – if you double-click on it, it will create a new document based on the template as described below. USING YOUR TEMPLATE 1. Double-click on the template file you created in the steps above.

Initiate a Template-Based Hire – Casual AUPE Hourly (Project) Step 2: Access Template Selection 1. Click the Look up Select Template button (magnifying glass) next to the Select Template field. The Look up Select Template window is displayed. Step 3: Select Template The template

P-245 - Term Contract Template for Gen. Services P-250 - Purchase Order Template P-520 - Equipment Lease Template P-530 - Equipment Maintenance Template P-600 - Professional Services Template P-601 – Professional Services Template (Individuals) P-606 - Chapter 6 Professional Services Template P-650 – Prof. Services Amendment Template

The symbol (a.k.a. tilde) means home account. Template - Dreamweaver allows you to save a webpage as a template. You can add editable regions to the template. Then you create web pages from the template. When you edit the template and save the changes, Dreamweaver updates all of the pages that are created from the template. Anything that you

Excel Template for Input Sales Invoice Template Sales CDN Template Advance Receipt Template Purchase Invoice Template Purchase CDN Template Advance Payment Template Download All Excel Templates If you create invoices on ClearTax GST (it’s FREE),

supplied for drawings (Draw) or spreadsheets (Calc). Using a template to create a document To use a template to create a document: 1) From the Menu bar, choose File New Templates to open the Template Manager dialog. Figure 1. Template Manager 2) From the tabs at the top of the dialog, select the Documents category (type) of template.

5. Create a Workflow Template 6. How to Set Workflow Template Options 7. Approve a PO with a Workflow Template Purchase Orders – Approve w/ Workflow In this lesson, you will learn how to create a PO workflow template, create and delete Team Members, and approving a PO with a workflow template. Topics inclu

EMAIL TEMPLATES Mailchimp Template 1 Mailchimp Template 2 Mailchimp Template 3 Mailchimp Template 4 Mailchimp Template 5 Mailchimp Template 6 Mailchimp Template 7 FLYERS Boat Diver Cuttlefish Seal Happy Diver (SI) IMAGES Underwater Topside The below assets can be downloaded and edited through Canva and the e

5S Template 279 5 Whys Template 281 A3 Template 282 Change Management Plan Template 284 Check Sheet 286 . Hoshin Kanri 291 Lessons Learned Survey Content 293 Meeting Minutes Template 296 Metrics Chain 297 Policy Template 298 Procedure Template 299 Process Map 300 Process Monitoring P

A Master’s Report Template Figure 3. A Zoomed-Out View of the Master’s Report Template in Microsoft Word Parts of the master’s report template The master’s report template begins with a README file that introduces how the template should be used. The formal parts of the template include the following: A cover or title page

TEMPLATE CSV FILE Use our template CSV file as a reference. Review the required . File Layout. and . Code List. above before using the template CSV file. Delete all of the headers (row 1) before attempting to import the CSV file. Columns with headers in capital letters are req

8. Import Plan Template (Excel tasks) You can export required Plan and Task details to Excel file and keep this file as Template (Refer section 7. Export Tasks). During Excel import, you can pick this template Excel file and Planner Manager will create new Plan and create Buckets and Tasks and add

A file pointer must be declared and used to access a file. Declaring a file pointer would be in this general form: FILE * ptr_name for example: FILE * inFile; // for an input file FILE * outFile; // for an output file inFile and outFile are just variable names, and as you know, you can name your variables whatever you want.

4.3 Save a Template Any changes can be saved, click on the "Save" button to save the changes. Or select “Save As Template” from the “File” menu. Or right click on the required template, and select “Save As Template” Enter a file name for the EEPROM template

supplied for drawings (Draw) or spreadsheets (Calc). Using a template to create a document To use a template to create a document: 1) From the Menu bar, choose File New Templates to open the Template Manager dialog. Figure 1: Template Manager 4 Working with Templates

Step 2. Create a template containing the required styles, fields, and other elements You can create your template from an existing document or template that contains some or all of the styles you want for this document, or you can create the template from a blank document. For more about

PRINTABLE PAGES Paper Christmas Tree Template 29 Moving Santa Legs Template 33 Christmas Shapes Sponge Template 30 Reindeer Ears Template Paper Plate Mask 34 Moving Santa Hat Template 31 Santa Hat Template Paper Plate Mask 35 Movin

Westside Barbell Template Working With the Standard Template By Jim Wendler For The Standard Template There is a great story from Dave about how the Standard Template originated. I've heard it 435 different times and it never gets old. But that's because Dave signs m

An introduction to literary studies/ Mario Klarer. p. cm. Includes bibliographical references and index. 1. English literature—History and criticism—Theory, etc. 2. American literature—History and criticism— Theory, etc. I. Title. PR21.K5213 1999 820.9–dc21 99–25771 CIP ISBN 0-203-97841-2 Master e-book ISBN ISBN 0-415-21169-7 (hbk)