{"id":5181,"date":"2023-03-07T09:32:45","date_gmt":"2023-03-07T09:32:45","guid":{"rendered":"https:\/\/info.documotor.com\/?page_id=5181"},"modified":"2023-03-07T09:32:45","modified_gmt":"2023-03-07T09:32:45","slug":"custom-functions-new-ui","status":"publish","type":"page","link":"https:\/\/info.documotor.com\/?page_id=5181","title":{"rendered":"Custom Functions (New UI)"},"content":{"rendered":"\n<p>In DocuMotor it is possible to define custom functions. These custom functions apply the transformations defined. This guide will describe how a custom function is configured.<\/p>\n\n\n\n<p>It is possible to use custom functions in other transformations e.g. in Templates. When calling a custom function it is required to use&nbsp;<code>#<\/code>&nbsp;in front of the function name. For example if a function is named&nbsp;<code>fullName<\/code>&nbsp;it should be refered in the transformations as&nbsp;<code>#fullName()<\/code>.<\/p>\n\n\n\n<p>The view is split into two panes, the function pane and the testing pane. The function pane, on the left, contains all functionality for the custom function itself. That is the parameters and the function transformation. The right pane, the testing pane, contains three text editors for testing if the custom function works. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"681\" src=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/03\/customFunction-1-1024x681.jpg\" alt=\"\" class=\"wp-image-5195\" srcset=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/03\/customFunction-1-1024x681.jpg 1024w, https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/03\/customFunction-1-300x200.jpg 300w, https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/03\/customFunction-1-768x511.jpg 768w, https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/03\/customFunction-1.jpg 1043w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3>The Function Pane<\/h3>\n\n\n\n<h4>Parameters<\/h4>\n\n\n\n<p>To be able to pass on parameters to the custom function it is required to define the parameters in the top of the function pane. To create a parameter the user clicks the plus button to the right of the <strong>Parameters<\/strong> label. Each parameter needs a name that should be used when writing the function\u2019s transformation in the&nbsp;text editor below.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" width=\"509\" height=\"240\" src=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/03\/image-2.png\" alt=\"\" class=\"wp-image-5199\" srcset=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/03\/image-2.png 509w, https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/03\/image-2-300x141.png 300w\" sizes=\"(max-width: 509px) 100vw, 509px\" \/><\/figure><\/div>\n\n\n\n<p><strong>By Value vs By Expression<\/strong><\/p>\n\n\n\n<p>A parameter can either be passed as&nbsp;<strong>by value<\/strong>&nbsp;or&nbsp;<strong>by expression<\/strong>. When a parameter is passed by value, it is evaluated when the function is called and the result is passed to the function. When a parameter is passed by expression it is not immediately evaluated on function call and instead evaluated in the scope where it is read in the function body. To pass a parameter by value, the <strong>ByValue<\/strong> label in the parameter should be turned on, which it is if it is purple. To pass a parameter by expression the user can toggle the <strong>ByValue <\/strong>label by clicking it and it will turn grey meaning that <strong>ByValue<\/strong> is turned off. <strong>ByValue<\/strong> is always turned on by default. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" width=\"279\" height=\"176\" src=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/03\/image-3.png\" alt=\"\" class=\"wp-image-5200\"\/><\/figure><\/div>\n\n\n\n<h4>Function Transformation<\/h4>\n\n\n\n<p>Below the parameters is a text editor where the JMES tranformation, that the custom function applies, is configured. This transformation should refer to the parameters defined above the text editor, if there is any. To refer to parameters, a <code>#<\/code> is put in from of the parameter name.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" width=\"388\" height=\"144\" src=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/03\/image-7.png\" alt=\"\" class=\"wp-image-5213\" srcset=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/03\/image-7.png 388w, https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/03\/image-7-300x111.png 300w\" sizes=\"(max-width: 388px) 100vw, 388px\" \/><\/figure><\/div>\n\n\n\n<h3>The Testing Pane<\/h3>\n\n\n\n<h4>Sample Data<\/h4>\n\n\n\n<p>The&nbsp;<strong>Sample Data<\/strong>&nbsp;text editor should contain an example of some sample data to test how to use data variables when calling the custom function.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" width=\"603\" height=\"154\" src=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/03\/image-8.png\" alt=\"\" class=\"wp-image-5214\" srcset=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/03\/image-8.png 603w, https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/03\/image-8-300x77.png 300w\" sizes=\"(max-width: 603px) 100vw, 603px\" \/><\/figure><\/div>\n\n\n\n<h4>Sample Transformation<\/h4>\n\n\n\n<p>The&nbsp;<strong>Sample Transformation<\/strong>&nbsp;text editor is used to test how to call the custom function. It is both possible to use hardcoded parameters or parameters from the&nbsp;<strong>Sample Data<\/strong>&nbsp;text editor. Below is an example of how to test call the function with both hardcoded parameters and parameters from the&nbsp;<strong>Sample Data<\/strong>.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" width=\"606\" height=\"147\" src=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/03\/image-9.png\" alt=\"\" class=\"wp-image-5215\" srcset=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/03\/image-9.png 606w, https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/03\/image-9-300x73.png 300w\" sizes=\"(max-width: 606px) 100vw, 606px\" \/><\/figure><\/div>\n\n\n\n<h4>Sample Result<\/h4>\n\n\n\n<p>The&nbsp;<strong>Sample Result<\/strong>&nbsp;shows the output from the&nbsp;<strong>Function Transformation<\/strong> in relation to how the <strong>Sample Transformation<\/strong> calls the function with hardcoded data or the <strong>Sample Data<\/strong>. The result of the above examples would look like this:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" width=\"606\" height=\"151\" src=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/03\/image-10.png\" alt=\"\" class=\"wp-image-5216\" srcset=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/03\/image-10.png 606w, https:\/\/info.documotor.com\/wp-content\/uploads\/2023\/03\/image-10-300x75.png 300w\" sizes=\"(max-width: 606px) 100vw, 606px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In DocuMotor it is possible to define custom functions. These custom functions apply the transformations defined. This guide will describe how a custom function is configured. It is possible to use custom functions in other transformations e.g. in Templates. When calling a custom function it is required to use&nbsp;#&nbsp;in front of the function name. For [&hellip;]<\/p>\n","protected":false},"author":17,"featured_media":0,"parent":3160,"menu_order":6,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/5181"}],"collection":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5181"}],"version-history":[{"count":16,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/5181\/revisions"}],"predecessor-version":[{"id":5247,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/5181\/revisions\/5247"}],"up":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3160"}],"wp:attachment":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}