{"id":21286,"date":"2022-04-11T13:56:06","date_gmt":"2022-04-11T11:56:06","guid":{"rendered":"https:\/\/help.openbee.com\/open-bee-scan-capture\/knowledge-base\/how-to-guides\/scripts-in-capture\/case-studies\/api-calls\/jse_database-retrieving-multiple-information-from-a-db-and-distributing-it-to-multiple-indexes-version-4-4-0\/"},"modified":"2026-05-13T09:36:47","modified_gmt":"2026-05-13T07:36:47","slug":"jse_database-retrieving-multiple-information-from-a-db-and-distributing-it-to-multiple-indexes-version-4-4-0","status":"publish","type":"page","link":"https:\/\/help.openbee.com\/en\/open-bee-scan-capture\/knowledge-base\/how-to-guides\/scripts-in-capture\/case-studies\/api-calls\/jse_database-retrieving-multiple-information-from-a-db-and-distributing-it-to-multiple-indexes-version-4-4-0\/","title":{"rendered":"JSE_Database: Retrieving Multiple Information from a DB and Distributing It to Multiple Indexes (Version 4.4.0)"},"content":{"rendered":"\n<p>In this particular case, we need to retrieve multiple pieces of information from a database from 1 query. This information is then distributed among several indexes in the document.<\/p>\n\n<p>So we&#8217;re going to use a primary index that is responsible for retrieving the data (Gateway required), and then several other indexes that will retrieve their information from the primary index (Context Capture only).  <\/p>\n\n<p>With this method, the processing time is reduced because only 1 script will use the DB and communication with the Gateway.<\/p>\n\n<pre class=\"wp-block-code\"><code>\/\/ Script principal\r\n\r\n\/\/ Un script pour tout r\u00e9cuperer\r\n\/\/ Ash nazg durbatul\u00fbk, ash nazg gimbatul, Ash nazg thrakatul\u00fbk agh burzum-ishi krimpatul\r\n\r\n\/\/Connexion DataBase\r\nvar database = new JSE_Database(\"DSN=SOURCE\");\r\n\r\n\/\/Envoi requ\u00eate + R\u00e9sultat\r\nvar req =\"SELECT * FROM SOURCE WHERE 1\";\r\nvar result = database.executeRequest(req);\r\n\r\nif(result.lengh &lt; 0)\r\n    return \"{}\";\r\n\r\n\/\/ Liste des variables \u00e0 r\u00e9cuperer dans le resultat et \u00e0 charger dans la structure JSON\r\nvar keys = &#91;\"val1\",\"val2\",\"val3\"];\r\n\/\/ On utilise une structure JSON cr\u00e9\u00e9 ici, car le r\u00e9sultat de la r\u00e9quete n'est pas un objet javascript convertible en json.\r\nvar structJson = {};\r\n\r\nfor (var i=0; i&lt;keys.length ; i++)\r\n\tstructJson&#91;keys&#91;i]] = result&#91;0]&#91;keys&#91;i]];\r\n\r\nreturn JSON.stringify(structJson);<\/code><\/pre>\n\n<pre class=\"wp-block-code\"><code>\/\/ Script \u00e0 utiliser dans chaque index pour r\u00e9cuperer l'information n\u00e9cessaire pour chaque index\r\n\r\n\/\/Appel des indexes :\r\nvar result = getTextFromIndexInfo(getFirstIndexFromID(pParameters,\"BDD_REQUEST_INDEX\"));\r\n\r\nif(result.lenght &lt;= 0)\r\n\treturn \"\";\r\n\r\nvar structJson = JSON.parse(result);\r\n\r\nreturn structJson&#91;'val1'];<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In this particular case, we need to retrieve multiple pieces of information from a database from 1 query. This information is then distributed among several indexes in the document. So we&#8217;re going to use a primary index that is responsible for retrieving the data (Gateway required), and then several other indexes that will retrieve their [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":21270,"menu_order":7,"comment_status":"closed","ping_status":"closed","template":"templates\/ob-help-products.php","meta":{"footnotes":""},"class_list":["post-21286","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/pages\/21286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/comments?post=21286"}],"version-history":[{"count":1,"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/pages\/21286\/revisions"}],"predecessor-version":[{"id":21288,"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/pages\/21286\/revisions\/21288"}],"up":[{"embeddable":true,"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/pages\/21270"}],"wp:attachment":[{"href":"https:\/\/help.openbee.com\/en\/wp-json\/wp\/v2\/media?parent=21286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}