{"id":11619,"date":"2019-05-22T17:44:45","date_gmt":"2019-05-22T17:44:45","guid":{"rendered":"https:\/\/www.directimpactsolutions.com\/?p=11619"},"modified":"2024-02-02T00:08:06","modified_gmt":"2024-02-02T00:08:06","slug":"how-to-use-the-new-data-file-script-steps-in-filemaker-18","status":"publish","type":"post","link":"https:\/\/www.directimpactsolutions.com\/en\/how-to-use-the-new-data-file-script-steps-in-filemaker-18\/","title":{"rendered":"How to Use the New Data File Script Steps in FileMaker 18"},"content":{"rendered":"<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"482\" src=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Script-Steps-1024x482.jpg\" alt=\"how to use the new data file script steps in FileMaker 18\" class=\"wp-image-11788\" style=\"width:667px;height:314px\" srcset=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Script-Steps-1024x482.jpg 1024w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Script-Steps-300x141.jpg 300w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Script-Steps-768x361.jpg 768w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Script-Steps-600x282.jpg 600w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Script-Steps.jpg 1275w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><p>FileMaker 18 offers a series of new script steps that add native file creation and manipulation to the developer\u2019s toolkit. The utility of these new script steps will be fully realized once people start using them, but right away I can foresee some great use cases. Write records to a text file for import into another system? Generate an HTML document? Custom local log files? All are possible with these new script steps.<\/p><blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Script steps are the set of commands, which are in the ScriptMaker feature, to be added to a script, in order to automate tasks or operations inside of your FileMaker app.<\/strong><\/p><cite>Claris International (<a href=\"https:\/\/support.claris.com\/s\/article\/Difference-Between-A-Script-Step-Vs-ScriptMaker-1503692942150?language=en_US#:~:text=To%20clarify%20some%20of%20the,operations%20inside%20of%20FileMaker%20Pro.\" target=\"_blank\" rel=\"noreferrer noopener\">source<\/a>)<\/cite><\/blockquote><h3 class=\"wp-block-heading\">What does script steps include?<\/h3><p>The script steps include:<\/p><ul class=\"wp-block-list\"><li>Create Data File<\/li>\n\n<li>Open Data File<\/li>\n\n<li>Get Data File Position<\/li>\n\n<li>Set Data File Position<\/li>\n\n<li>Get File Exists<\/li>\n\n<li>Get File Size<\/li>\n\n<li>Write to Data File<\/li>\n\n<li>Read from Data File<\/li>\n\n<li>Rename File<\/li>\n\n<li>Close Data File<\/li>\n\n<li>Delete File<\/li><\/ul><p>Plus the function<\/p><ul class=\"wp-block-list\"><li>Get ( OpenDataFileInfo )<\/li><\/ul><p>Some of these script steps are simple file system functions, enabling FileMaker to interact more easily with the Mac\u2019s Finder or Windows Explorer.&nbsp;<em>Delete File<\/em>&nbsp;does just that \u2013 it just deletes a named file from disk. Likewise,&nbsp;<em>Rename File<\/em>,&nbsp;<em>Get File Size<\/em>&nbsp;and&nbsp;<em>Get File Exists<\/em>&nbsp;do more or less what you would expect. Interestingly,&nbsp;<em>Delete File<\/em>&nbsp;and&nbsp;<em>Rename File&nbsp;<\/em>give no confirmation dialog or warning. It seems you can do just about whatever you like with them, including appending a completely different file extension or wipe out a file completely (<em>Delete File<\/em>&nbsp;doesn\u2019t just stick it in the recycle bin or trash; it fully deletes it). Definitely use these with caution!<\/p><p>Things get a bit more interesting with the rest of the script steps. With these, you can actually create a file on disk, with any file extension you want, and as far as I can tell, any format you can write with text. This includes an HTML file, CSV, Tab-delimited text, plain text, JSON, a log file, a Base64 encoded image, a CSS library, whatever! As an example, I\u2019ll show you how to export records to a basic text file on the desktop.<\/p><h3 class=\"wp-block-heading\">Create a text file<\/h3><p>The first script step to use will be a \u201cSet Variable\u201d, in which you\u2019ll want to set up a filename and file path:<\/p><pre class=\"wp-block-code\"><code><strong>Set Variable<\/strong> &#91; $fileName; Value:Get ( DesktopPath ) &amp; \"18_dataFile.txt\" ] <\/code><\/pre><p>Next you\u2019ll want to check to see if the file exists already on disk (not strictly necessary, but you may want to handle it if the file does already exist). If the file doesn\u2019t exist you can create it using the \u201cCreate Data File\u201d step:<\/p><pre class=\"wp-block-code\"><code><strong>Get File Exists<\/strong> &#91; \u201c$fileName\u201d ; Target: $exists ] \n#results in boolean 1 if $fileName exists\n<strong>If<\/strong> &#91; not $exists ] \n #create an empty file \n <strong>Create Data File<\/strong> &#91; \u201c$fileName\u201d ; Create folders: Off ] \n<strong>End If <\/strong> <\/code><\/pre><p>Now that we\u2019ve created a blank data file, we need to open it:<\/p><pre class=\"wp-block-code\"><code>#open the empty file \n<strong>Open Data File<\/strong> &#91; \u201c$fileName\u201d ; Target: $dataFile ]<\/code><\/pre><p>Once we have the file in memory, we need to get an ID from it using the new&nbsp;<em>Get (OpenDataFileInfo)<\/em>&nbsp;function. This step is crucial, because the ID of this file is required when referencing it in other script steps. When using this function, the file info is returned in the format:<\/p><pre class=\"wp-block-code\"><code>1    file:\/Macintosh HD\/Users\/davidweiner\/Desktop\/18_dataFile.txt<\/code><\/pre><p>The first number is the actual file ID, which is what we need. The space between the ID and the file name is actually a&nbsp;<em>Tab<\/em>&nbsp;character, and there are a number of ways you could extract the ID from this. I used a&nbsp;<em>Substitute&nbsp;<\/em>function to change the&nbsp;<em>Tab<\/em>&nbsp;to a&nbsp;<em>Pilcrow<\/em>, and then extracted the first value in the list to get our ID:<\/p><pre class=\"wp-block-code\"><code>#get the file ID using the Get ( OpenDataFileInfo ) function \n<strong>Set Variable<\/strong> &#91; $fileID; Value:\n  GetValue (Substitute (Get (OpenDataFileInfo); \" \" ; \u00b6 ); 1 )] <\/code><\/pre><p>Now that we have a file open, and an ID to reference it, we can begin to write data into it. For this demo I set up a simple looping script, gathered some Contact data from each record into a JSON blob, and inserted the lines into the open data file one at a time:<\/p><pre class=\"wp-block-code\"><code>#insert JSON records into the file \n<strong>Go to Record\/Request\/Page<\/strong> \n &#91; First ] \n\n<strong>Loop<\/strong>\n\n  <strong>Set Variable<\/strong> &#91; $json; Value:JSONSetElement ( \"{}\" ;\n   &#91; \"id\" ; Contacts::PrimaryKey ; JSONString ]; \n   &#91; \"first\" ; Contacts::First Name ; JSONString ]; \n   &#91; \"last\" ; Contacts::Last Name ; JSONString ] )] \n  \n <strong> Write to Data File<\/strong> &#91; File ID: $fileID ; \n    Data source: $json ; Write as: UTF-16 ; Append line feed: On ] \n\n  <strong>Go to Record\/Request\/Page <\/strong>\n   &#91; Next; Exit after last ] \n\n<strong>End Loop<\/strong><\/code><\/pre><p>Once the loop is complete, we want to make sure to close the data file, otherwise we\u2019ll be left with copies open in memory:<\/p><pre class=\"wp-block-code\"><code><strong>Close Data File<\/strong> &#91; File ID: $fileID ] <\/code><\/pre><p>After the script has completed running, we have a text file on the desktop, named&nbsp;<em>18_dataFile.txt<\/em>&nbsp;with the following contents:<\/p><pre class=\"wp-block-code\"><code>{\"first\":\"David\",\"id\":\"6210418C\",\"last\":\"Weiner\"}\n{\"first\":\"Eleanor\",\"id\":\"BCDDC24E\",\"last\":\"Fulton\"}\n{\"first\":\"Karl\",\"id\":\"DFA3F16D\",\"last\":\"Jreijiri\"}\n{\"first\":\"Kimberly\",\"id\":\"E5032653\",\"last\":\"Carlson\"}\n{\"first\":\"Matt\",\"id\":\"1B412835\",\"last\":\"Navarre\"}\n{\"first\":\"Michelle\",\"id\":\"B5B19E5D\",\"last\":\"Davison\"}\n{\"first\":\"Paul\",\"id\":\"DF8DAE5C\",\"last\":\"Beyrouty\"}\n{\"first\":\"Shawn\",\"id\":\"302FD01D\",\"last\":\"Prado\"}\n<\/code><\/pre><p>That\u2019s it! Once you\u2019ve figured out the basics of inserting text into a file from a FileMaker script, the possibilities are endless. What use cases can you think of? Feel free to <a href=\"http:\/\/directimpactsolutions.com\/en\/contact-us\/\">contact us<\/a> if you have a project in mind!<\/p><hr class=\"wp-block-separator has-alpha-channel-opacity\" style=\"margin-top:var(--wp--preset--spacing--70);margin-bottom:var(--wp--preset--spacing--70)\"\/><p class=\"has-small-font-size\"><em>*This article was originally written for AppWorks, which has since joined Direct Impact Solutions. This article is intended for informative purposes only. To the best of our knowledge, this information is accurate as of the date of publication.<\/em><\/p>","protected":false},"excerpt":{"rendered":"<p>FileMaker 18 offers a series of new script steps that add native file creation and manipulation to the developer\u2019s toolkit. The utility of these new script steps will be fully realized once people start using them, but right away I can foresee some great use cases. Write records to a text file for import into &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/www.directimpactsolutions.com\/en\/how-to-use-the-new-data-file-script-steps-in-filemaker-18\/\"> <span class=\"screen-reader-text\">How to Use the New Data File Script Steps in FileMaker 18<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":23,"featured_media":11788,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","footnotes":""},"categories":[29],"tags":[39],"class_list":["post-11619","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-low-code","tag-filemaker"],"uagb_featured_image_src":{"full":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Script-Steps.jpg",1275,600,false],"thumbnail":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Script-Steps-150x150.jpg",150,150,true],"medium":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Script-Steps-300x141.jpg",300,141,true],"medium_large":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Script-Steps-768x361.jpg",768,361,true],"large":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Script-Steps-1024x482.jpg",1024,482,true],"1536x1536":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Script-Steps.jpg",1275,600,false],"2048x2048":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Script-Steps.jpg",1275,600,false],"woocommerce_thumbnail":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Script-Steps-300x300.jpg",300,300,true],"woocommerce_single":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Script-Steps-600x282.jpg",600,282,true],"woocommerce_gallery_thumbnail":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Script-Steps-100x100.jpg",100,100,true]},"uagb_author_info":{"display_name":"David Weiner","author_link":"https:\/\/www.directimpactsolutions.com\/en\/author\/david-weiner\/"},"uagb_comment_info":1,"uagb_excerpt":"FileMaker 18 offers a series of new script steps that add native file creation and manipulation to the developer\u2019s toolkit. The utility of these new script steps will be fully realized once people start using them, but right away I can foresee some great use cases. Write records to a text file for import into&hellip;","_links":{"self":[{"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/posts\/11619","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/users\/23"}],"replies":[{"embeddable":true,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/comments?post=11619"}],"version-history":[{"count":3,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/posts\/11619\/revisions"}],"predecessor-version":[{"id":16610,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/posts\/11619\/revisions\/16610"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/media\/11788"}],"wp:attachment":[{"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/media?parent=11619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/categories?post=11619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/tags?post=11619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}