Search code examples
jsonuser-controlsgenexus

Store User Control JSON object in DB


I have a JSON object that I want to store in a database. The JSON is generated by an User Control.

The JSON object:

var datatosend = {
        isit: isitArray,
        ec: ecArray,
        bc: bcArray,
        bb: bbArray,
        io: ioArray
};

What is the best way to record a JSON object in the database using GeneXus?

Edit:

var isitArray = getObjectsRequest('isit', isitID);
var ecArray = getObjectsRequest('ec', ecID);
var bcArray = getObjectsRequest('bc', bcID);
var bbArray = getObjectsRequest('bb', bbID);
var ioArray = getObjectsRequest('io', ioID);

function getObjectsRequest(type, compId){
    var array = [];
    for (var i = 0; i<compId; i++) {
        var comp = mainLayer.find('#'+ type + i)[0];
        array.push({
            xposition: comp.getX(),
            yposition: comp.getY(),
            titleid: comp.getId(),
            description: comp.find('.textDescription')[0].getText(),
            leftrelationsids: comp.leftCRelations,
            rightrelationsids: comp.rightCRelations
        });
    };
    return array;
}

var datatosend = {
        isit: isitArray,
        ec: ecArray,
        bc: bcArray,
        bb: bbArray,
        io: ioArray
};

Solution

  • You can use a LongVarChar attribute to store the JSON, but you'll need to convert the JavaScript object to String first.