{"id":4853,"date":"2023-05-11T20:45:52","date_gmt":"2023-05-11T18:45:52","guid":{"rendered":"https:\/\/help.r2docuo.com\/knowledge-base\/how-to-check-a-condition-each-time-a-document-is-saved\/"},"modified":"2024-02-23T09:56:37","modified_gmt":"2024-02-23T08:56:37","slug":"how-to-check-a-condition-each-time-a-document-is-saved","status":"publish","type":"ht_kb","link":"https:\/\/help.r2docuo.com\/en\/knowledge-base\/how-to-check-a-condition-each-time-a-document-is-saved\/","title":{"rendered":"JavaScript formula control when saving a document"},"content":{"rendered":"\n<p>The <strong>Control <\/strong>step of Docuo&#8217;s Category Wizard is the right place to prevent your users from performing an action even when folder and category permissions allow them to do so.  <\/p>\n\n<p>It is possible to <strong>create a control that checks a condition before saving a document<\/strong>. We can also prepare an error message explaining to the user why he\/she cannot save when the condition is not met.<\/p>\n\n<p>We will explain the operation of this type of control with an example. Suppose we have a category with the following fields:<\/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=\"fields\" 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>In our example we want to prevent documents with a total price of less than 1,000 euros from being saved.<\/p>\n\n<p>To do so, we create a new control:<\/p>\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1002\" height=\"242\" src=\"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-7.png\" alt=\"Docuo Category Assistant, Control step\" class=\"wp-image-4831\" srcset=\"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-7.png 1002w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-7-600x145.png 600w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-7-768x185.png 768w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-7-50x12.png 50w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-7-60x14.png 60w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-7-100x24.png 100w\" sizes=\"auto, (max-width: 1002px) 100vw, 1002px\" \/><\/figure>\n\n<p>The new control creation window allows you to set what you want to control by means of two drop-down lists<\/p>\n\n<h2 class=\"wp-block-heading\">Selection of the action to be controlled<\/h2>\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-8.png\"><img loading=\"lazy\" decoding=\"async\" width=\"984\" height=\"269\" src=\"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-8.png\" alt=\"Creating a new control: Action drop-down list\" class=\"wp-image-4833\" srcset=\"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-8.png 984w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-8-600x164.png 600w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-8-768x210.png 768w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-8-50x14.png 50w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-8-60x16.png 60w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-8-100x27.png 100w\" sizes=\"auto, (max-width: 984px) 100vw, 984px\" \/><\/a><\/figure>\n\n<p>The first thing to do is to <strong>choose the action you want to control<\/strong> from the drop-down list on the right. In this case we will choose <em>&#8220;Save documents that meet the following condition&#8221;<\/em>.<\/p>\n\n<h2 class=\"wp-block-heading\">Creating the condition formula<\/h2>\n\n<p>Then we must <strong>enter the condition we want to verify<\/strong> in the control by <strong>means of a JavaScript formula<\/strong>.<\/p>\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\">The formula must return the empty string in cases where the control is exceeded, and a descriptive error message in cases where it is not exceeded.<\/p>\n\n<p>In our case, the formula should return the empty string when the total price of the offer exceeds 1.000 \u20ac, <strong>and an error message otherwise<\/strong>:<\/p>\n\n<pre class=\"wp-block-code\"><code>if(&lt;@Offer pricing:Total&gt; &gt;= 1000){\n    return '';\n} else {\n    return 'No es posible guardar ofertas de menos de 1.000 \u20ac';\n}<\/code><\/pre>\n\n<h2 class=\"wp-block-heading\">Choose which users the control should apply to<\/h2>\n\n<p>The next thing to do is to choose which users will be affected by the control. This is done by assigning users and groups:<\/p>\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"520\" height=\"142\" src=\"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-15.png\" alt=\"\" class=\"wp-image-4847\" srcset=\"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-15.png 520w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-15-50x14.png 50w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-15-60x16.png 60w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-15-100x27.png 100w\" sizes=\"auto, (max-width: 520px) 100vw, 520px\" \/><\/figure>\n\n<p>In our case, we will choose the commercials. They will not be able to keep bids of less than 1.000 \u20ac.<\/p>\n\n<h2 class=\"wp-block-heading\">Choose what happens to other users<\/h2>\n\n<p>In Docuo you can set controls that affect only a group of users <strong>or that, in addition, prevent an action for the rest<\/strong>. To do so, we display the &#8220;Action&#8221; list:<\/p>\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"443\" height=\"273\" src=\"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-12.png\" alt=\"\" class=\"wp-image-4841\" srcset=\"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-12.png 443w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-12-50x31.png 50w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-12-60x37.png 60w, https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image-12-100x62.png 100w\" sizes=\"auto, (max-width: 443px) 100vw, 443px\" \/><\/figure>\n\n<p>If you choose &#8220;Prevent&#8221;, the users you specify will be affected by the control, but <strong>the rest of the users will be able to perform the action<\/strong>.<\/p>\n\n<p>If you choose <em>&#8220;Control only&#8221;<\/em>, the users you specify will also be affected by the control, <strong>but the rest of the users will not be able to perform the action<\/strong>.<\/p>\n\n<p>Thus, in our case, if we choose <em>&#8220;Prevent&#8221;<\/em>, users who are not in the &#8220;Commercial&#8221; group will be able to save offers of less than 1,000 \u20ac.  <\/p>\n\n<p>If we were to choose <em>&#8220;Check that only&#8221;<\/em>, <strong>the rest of the users would not be able to save offers<\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Control step of Docuo&#8217;s Category Wizard is the right place to prevent your users from performing an action even when folder and category permissions allow them to do so. It is possible to create a control that checks a condition before saving a document. We can also prepare an&#8230;<\/p>\n","protected":false},"author":1,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":{"content-type":"","footnotes":""},"ht-kb-category":[64],"ht-kb-tag":[],"class_list":["post-4853","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-control"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>JavaScript formula control when saving a document - 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=\"JavaScript formula control when saving a document - R2 Docuo | Help center\" \/>\n<meta property=\"og:description\" content=\"The Control step of Docuo&#8217;s Category Wizard is the right place to prevent your users from performing an action even when folder and category permissions allow them to do so. It is possible to create a control that checks a condition before saving a document. We can also prepare an...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/help.r2docuo.com\/en\/knowledge-base\/how-to-check-a-condition-each-time-a-document-is-saved\/\" \/>\n<meta property=\"og:site_name\" content=\"R2 Docuo | Help center\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-23T08:56:37+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-check-a-condition-each-time-a-document-is-saved\\\/\",\"url\":\"https:\\\/\\\/help.r2docuo.com\\\/en\\\/knowledge-base\\\/how-to-check-a-condition-each-time-a-document-is-saved\\\/\",\"name\":\"JavaScript formula control when saving a document - R2 Docuo | Help center\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/help.r2docuo.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/help.r2docuo.com\\\/en\\\/knowledge-base\\\/how-to-check-a-condition-each-time-a-document-is-saved\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/help.r2docuo.com\\\/en\\\/knowledge-base\\\/how-to-check-a-condition-each-time-a-document-is-saved\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/help.r2docuo.com\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/image.png\",\"datePublished\":\"2023-05-11T18:45:52+00:00\",\"dateModified\":\"2024-02-23T08:56:37+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/help.r2docuo.com\\\/en\\\/knowledge-base\\\/how-to-check-a-condition-each-time-a-document-is-saved\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/help.r2docuo.com\\\/en\\\/knowledge-base\\\/how-to-check-a-condition-each-time-a-document-is-saved\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/help.r2docuo.com\\\/en\\\/knowledge-base\\\/how-to-check-a-condition-each-time-a-document-is-saved\\\/#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-check-a-condition-each-time-a-document-is-saved\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Portada\",\"item\":\"https:\\\/\\\/help.r2docuo.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript formula control when saving a document\"}]},{\"@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":"JavaScript formula control when saving a document - 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":"JavaScript formula control when saving a document - R2 Docuo | Help center","og_description":"The Control step of Docuo&#8217;s Category Wizard is the right place to prevent your users from performing an action even when folder and category permissions allow them to do so. It is possible to create a control that checks a condition before saving a document. We can also prepare an...","og_url":"https:\/\/help.r2docuo.com\/en\/knowledge-base\/how-to-check-a-condition-each-time-a-document-is-saved\/","og_site_name":"R2 Docuo | Help center","article_modified_time":"2024-02-23T08:56:37+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-check-a-condition-each-time-a-document-is-saved\/","url":"https:\/\/help.r2docuo.com\/en\/knowledge-base\/how-to-check-a-condition-each-time-a-document-is-saved\/","name":"JavaScript formula control when saving a document - R2 Docuo | Help center","isPartOf":{"@id":"https:\/\/help.r2docuo.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/help.r2docuo.com\/en\/knowledge-base\/how-to-check-a-condition-each-time-a-document-is-saved\/#primaryimage"},"image":{"@id":"https:\/\/help.r2docuo.com\/en\/knowledge-base\/how-to-check-a-condition-each-time-a-document-is-saved\/#primaryimage"},"thumbnailUrl":"https:\/\/help.r2docuo.com\/wp-content\/uploads\/2023\/05\/image.png","datePublished":"2023-05-11T18:45:52+00:00","dateModified":"2024-02-23T08:56:37+00:00","breadcrumb":{"@id":"https:\/\/help.r2docuo.com\/en\/knowledge-base\/how-to-check-a-condition-each-time-a-document-is-saved\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/help.r2docuo.com\/en\/knowledge-base\/how-to-check-a-condition-each-time-a-document-is-saved\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/help.r2docuo.com\/en\/knowledge-base\/how-to-check-a-condition-each-time-a-document-is-saved\/#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-check-a-condition-each-time-a-document-is-saved\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Portada","item":"https:\/\/help.r2docuo.com\/"},{"@type":"ListItem","position":2,"name":"JavaScript formula control when saving a document"}]},{"@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\/4853","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=4853"}],"version-history":[{"count":0,"href":"https:\/\/help.r2docuo.com\/en\/wp-json\/wp\/v2\/ht-kb\/4853\/revisions"}],"wp:attachment":[{"href":"https:\/\/help.r2docuo.com\/en\/wp-json\/wp\/v2\/media?parent=4853"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/help.r2docuo.com\/en\/wp-json\/wp\/v2\/ht-kb-category?post=4853"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/help.r2docuo.com\/en\/wp-json\/wp\/v2\/ht-kb-tag?post=4853"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}