{"id":4829,"date":"2023-05-11T16:10:22","date_gmt":"2023-05-11T14:10:22","guid":{"rendered":"https:\/\/help.r2docuo.com\/knowledge-base\/how-to-test-javascript-formulas-in-docuo\/"},"modified":"2023-05-11T20:46:45","modified_gmt":"2023-05-11T18:46:45","slug":"how-to-test-javascript-formulas-in-docuo","status":"publish","type":"ht_kb","link":"https:\/\/help.r2docuo.com\/en\/knowledge-base\/how-to-test-javascript-formulas-in-docuo\/","title":{"rendered":"How to test JavaScript formulas in Docuo"},"content":{"rendered":"\n<p>Formulas are used in Docuo for multiple purposes. From calculating the value of a field, to determining whether it is visible or not, or whether it should be locked.<\/p>\n\n<p>Docuo&#8217;s formula editor allows you to test a JavaScript formula while it is being edited.  <\/p>\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-success\">Testing JavaScript formulas before saving them ensures that they behave correctly <strong>without having to close the category editor and that the changes are applied to all documents<\/strong> in the category.<\/p>\n\n<p>Suppose we have a Commercial Offers category with some price fields that include formulas:<\/p>\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"481\" height=\"276\" src=\"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image.png\" alt=\"\" class=\"wp-image-4812\" srcset=\"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image.png 481w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-50x29.png 50w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-60x34.png 60w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-100x57.png 100w\" sizes=\"auto, (max-width: 481px) 100vw, 481px\" \/><\/figure>\n\n<p>Let&#8217;s edit the formula of the total field, which multiplies the price by the units and applies a discount percentage. To do this, select the field details and go to the options tab in the Formula section:<\/p>\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"647\" height=\"242\" src=\"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-1.png\" alt=\"\" class=\"wp-image-4814\" srcset=\"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-1.png 647w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-1-600x224.png 600w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-1-50x19.png 50w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-1-60x22.png 60w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-1-100x37.png 100w\" sizes=\"auto, (max-width: 647px) 100vw, 647px\" \/><\/figure>\n\n<p>Click on the button on the right to access the formula editor:<\/p>\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"678\" height=\"148\" src=\"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-4.png\" alt=\"\" class=\"wp-image-4820\" srcset=\"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-4.png 678w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-4-600x131.png 600w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-4-50x11.png 50w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-4-60x13.png 60w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-4-100x22.png 100w\" sizes=\"auto, (max-width: 678px) 100vw, 678px\" \/><\/figure>\n\n<p>To the right of the button bar we see &#8220;Test formula&#8221;:<\/p>\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-6.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1004\" height=\"724\" src=\"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-6.png\" alt=\"\" class=\"wp-image-4824\" srcset=\"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-6.png 1004w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-6-600x433.png 600w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-6-768x554.png 768w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-6-50x36.png 50w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-6-60x43.png 60w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-6-100x72.png 100w\" sizes=\"auto, (max-width: 1004px) 100vw, 1004px\" \/><\/a><\/figure>\n\n<p>In the pop-up side panel, we can test the formula. First we must choose whether we want to test with a new document window, or by choosing an existing document, in which case its data will be loaded.<\/p>\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\">Choose the &#8220;Use an existing document&#8221; option to debug specific cases, in documents where your formula does not behave as expected.<\/p>\n\n<p>The green check indicates that the syntax is correct.<\/p>\n\n<p>The field whose formula is being edited is shown in yellow.<\/p>\n\n<p>We can then enter test data in the fields used in the formula to check that the calculations are correct.<\/p>\n\n<p>You can modify the document state to see how the formula would behave in different states.<\/p>\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-alert\">You can use the test panel with peace of mind, no document will be modified during the test, even if you have chosen it for testing.<\/p>\n\n<p>You can make changes to the JavaScript formula while you have the test panel open. In this case, in <strong>order for the changes in the JavaScript code to be applied, you must click the &#8220;Execute&#8221; button<\/strong>.<\/p>\n\n<p><\/p>\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Formulas are used in Docuo for multiple purposes. From calculating the value of a field, to determining whether it is visible or not, or whether it should be locked. Docuo&#8217;s formula editor allows you to test a JavaScript formula while it is being edited. Suppose we have a Commercial Offers&#8230;<\/p>\n","protected":false},"author":1,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":{"content-type":"","footnotes":""},"ht-kb-category":[75],"ht-kb-tag":[],"class_list":["post-4829","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-formulas"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to test JavaScript formulas in Docuo - R2 Docuo | Help center<\/title>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to test JavaScript formulas in Docuo - R2 Docuo | Help center\" \/>\n<meta property=\"og:description\" content=\"Formulas are used in Docuo for multiple purposes. From calculating the value of a field, to determining whether it is visible or not, or whether it should be locked. Docuo&#8217;s formula editor allows you to test a JavaScript formula while it is being edited. Suppose we have a Commercial Offers...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/help.r2docuo.com\/en\/knowledge-base\/how-to-test-javascript-formulas-in-docuo\/\" \/>\n<meta property=\"og:site_name\" content=\"R2 Docuo | Help center\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-11T18:46:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@R2Docuo\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/help.r2docuo.com\\\/en\\\/knowledge-base\\\/how-to-test-javascript-formulas-in-docuo\\\/\",\"url\":\"https:\\\/\\\/help.r2docuo.com\\\/en\\\/knowledge-base\\\/how-to-test-javascript-formulas-in-docuo\\\/\",\"name\":\"How to test JavaScript formulas in Docuo - R2 Docuo | Help center\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/help.r2docuo.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/help.r2docuo.com\\\/en\\\/knowledge-base\\\/how-to-test-javascript-formulas-in-docuo\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/help.r2docuo.com\\\/en\\\/knowledge-base\\\/how-to-test-javascript-formulas-in-docuo\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/help.r2docuo.com\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/image.png\",\"datePublished\":\"2023-05-11T14:10:22+00:00\",\"dateModified\":\"2023-05-11T18:46:45+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/help.r2docuo.com\\\/en\\\/knowledge-base\\\/how-to-test-javascript-formulas-in-docuo\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/help.r2docuo.com\\\/en\\\/knowledge-base\\\/how-to-test-javascript-formulas-in-docuo\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/help.r2docuo.com\\\/en\\\/knowledge-base\\\/how-to-test-javascript-formulas-in-docuo\\\/#primaryimage\",\"url\":\"https:\\\/\\\/help.r2docuo.com\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/image.png\",\"contentUrl\":\"https:\\\/\\\/help.r2docuo.com\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/image.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/help.r2docuo.com\\\/en\\\/knowledge-base\\\/how-to-test-javascript-formulas-in-docuo\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Portada\",\"item\":\"https:\\\/\\\/help.r2docuo.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to test JavaScript formulas in Docuo\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/help.r2docuo.com\\\/#website\",\"url\":\"https:\\\/\\\/help.r2docuo.com\\\/\",\"name\":\"R2 Docuo | Help center\",\"description\":\"Todos los recursos para usuarios, administradores y desarrolladores de de R2 Docuo a tu alcance\",\"publisher\":{\"@id\":\"https:\\\/\\\/help.r2docuo.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/help.r2docuo.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/help.r2docuo.com\\\/#organization\",\"name\":\"R2 Docuo | Help center\",\"url\":\"https:\\\/\\\/help.r2docuo.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/help.r2docuo.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/help.r2docuo.com\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/ILUDEST_CENTRODEAYUDA.png\",\"contentUrl\":\"https:\\\/\\\/help.r2docuo.com\\\/wp-content\\\/uploads\\\/2023\\\/06\\\/ILUDEST_CENTRODEAYUDA.png\",\"width\":1200,\"height\":630,\"caption\":\"R2 Docuo | Help center\"},\"image\":{\"@id\":\"https:\\\/\\\/help.r2docuo.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/R2Docuo\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/r2docuo\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to test JavaScript formulas in Docuo - R2 Docuo | Help center","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"How to test JavaScript formulas in Docuo - R2 Docuo | Help center","og_description":"Formulas are used in Docuo for multiple purposes. From calculating the value of a field, to determining whether it is visible or not, or whether it should be locked. Docuo&#8217;s formula editor allows you to test a JavaScript formula while it is being edited. Suppose we have a Commercial Offers...","og_url":"https:\/\/help.r2docuo.com\/en\/knowledge-base\/how-to-test-javascript-formulas-in-docuo\/","og_site_name":"R2 Docuo | Help center","article_modified_time":"2023-05-11T18:46:45+00:00","og_image":[{"url":"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image.png","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_site":"@R2Docuo","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/help.r2docuo.com\/en\/knowledge-base\/how-to-test-javascript-formulas-in-docuo\/","url":"https:\/\/help.r2docuo.com\/en\/knowledge-base\/how-to-test-javascript-formulas-in-docuo\/","name":"How to test JavaScript formulas in Docuo - R2 Docuo | Help center","isPartOf":{"@id":"https:\/\/help.r2docuo.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/help.r2docuo.com\/en\/knowledge-base\/how-to-test-javascript-formulas-in-docuo\/#primaryimage"},"image":{"@id":"https:\/\/help.r2docuo.com\/en\/knowledge-base\/how-to-test-javascript-formulas-in-docuo\/#primaryimage"},"thumbnailUrl":"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image.png","datePublished":"2023-05-11T14:10:22+00:00","dateModified":"2023-05-11T18:46:45+00:00","breadcrumb":{"@id":"https:\/\/help.r2docuo.com\/en\/knowledge-base\/how-to-test-javascript-formulas-in-docuo\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/help.r2docuo.com\/en\/knowledge-base\/how-to-test-javascript-formulas-in-docuo\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/help.r2docuo.com\/en\/knowledge-base\/how-to-test-javascript-formulas-in-docuo\/#primaryimage","url":"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image.png","contentUrl":"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image.png"},{"@type":"BreadcrumbList","@id":"https:\/\/help.r2docuo.com\/en\/knowledge-base\/how-to-test-javascript-formulas-in-docuo\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Portada","item":"https:\/\/help.r2docuo.com\/"},{"@type":"ListItem","position":2,"name":"How to test JavaScript formulas in Docuo"}]},{"@type":"WebSite","@id":"https:\/\/help.r2docuo.com\/#website","url":"https:\/\/help.r2docuo.com\/","name":"R2 Docuo | Help center","description":"Todos los recursos para usuarios, administradores y desarrolladores de de R2 Docuo a tu alcance","publisher":{"@id":"https:\/\/help.r2docuo.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/help.r2docuo.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/help.r2docuo.com\/#organization","name":"R2 Docuo | Help center","url":"https:\/\/help.r2docuo.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/help.r2docuo.com\/#\/schema\/logo\/image\/","url":"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/06\/ILUDEST_CENTRODEAYUDA.png","contentUrl":"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/06\/ILUDEST_CENTRODEAYUDA.png","width":1200,"height":630,"caption":"R2 Docuo | Help center"},"image":{"@id":"https:\/\/help.r2docuo.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/R2Docuo","https:\/\/www.linkedin.com\/company\/r2docuo"]}]}},"_links":{"self":[{"href":"https:\/\/help.r2docuo.com\/en\/wp-json\/wp\/v2\/ht-kb\/4829","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/help.r2docuo.com\/en\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/help.r2docuo.com\/en\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/help.r2docuo.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/help.r2docuo.com\/en\/wp-json\/wp\/v2\/comments?post=4829"}],"version-history":[{"count":0,"href":"https:\/\/help.r2docuo.com\/en\/wp-json\/wp\/v2\/ht-kb\/4829\/revisions"}],"wp:attachment":[{"href":"https:\/\/help.r2docuo.com\/en\/wp-json\/wp\/v2\/media?parent=4829"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/help.r2docuo.com\/en\/wp-json\/wp\/v2\/ht-kb-category?post=4829"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/help.r2docuo.com\/en\/wp-json\/wp\/v2\/ht-kb-tag?post=4829"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}