JSE_Database: Retrieving Multiple Information from a DB and Distributing It to Multiple Indexes (Version 4.4.0)

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’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).

With this method, the processing time is reduced because only 1 script will use the DB and communication with the Gateway.

// Script principal

// Un script pour tout récuperer
// Ash nazg durbatulûk, ash nazg gimbatul, Ash nazg thrakatulûk agh burzum-ishi krimpatul

//Connexion DataBase
var database = new JSE_Database("DSN=SOURCE");

//Envoi requête + Résultat
var req ="SELECT * FROM SOURCE WHERE 1";
var result = database.executeRequest(req);

if(result.lengh < 0)
    return "{}";

// Liste des variables à récuperer dans le resultat et à charger dans la structure JSON
var keys = ["val1","val2","val3"];
// On utilise une structure JSON créé ici, car le résultat de la réquete n'est pas un objet javascript convertible en json.
var structJson = {};

for (var i=0; i<keys.length ; i++)
	structJson[keys[i]] = result[0][keys[i]];

return JSON.stringify(structJson);
// Script à utiliser dans chaque index pour récuperer l'information nécessaire pour chaque index

//Appel des indexes :
var result = getTextFromIndexInfo(getFirstIndexFromID(pParameters,"BDD_REQUEST_INDEX"));

if(result.lenght <= 0)
	return "";

var structJson = JSON.parse(result);

return structJson['val1'];