Skip to content
Snippets Groups Projects
conditionProcess.js 970 B
import("system.db");
import("system.result");
import("Sql_lib");
import("Keyword_lib");

var relId, cond;
cond = new SqlCondition();

cond.andPrepareVars("COMM.RELATION_ID", "$param.RelId_param");

if (vars.exists("$param.MediumCategoriesFilter_param")){
    mediumCategories = vars.get("$param.MediumCategoriesFilter_param");
    if (mediumCategories != null && mediumCategories != "") {
        mediumCategories = text.decodeMS(mediumCategories);   
        keywordUtil = new KeywordUtils();
        var kwd = keywordUtil.createKeyword("COMM.MEDIUM");
        kwd.filter(function(id, name, customs){
            return mediumCategories.indexOf(customs.category) > -1;
        });
        mediumIds = kwd.toArray("id");
        if (mediumIds.length == 0)
            throw new Error();//TODO: add message

        cond.and("COMM.MEDIUM_ID in (" + mediumIds.join(", ") + ")");
    }
}

result.string(db.translateCondition([cond.toString("1 = 2"), cond.preparedValues]));