Como colocar parâmetros no Dataset customizado?

Olá pessoal.

É possível colocar parâmetros no Dataset customizado?

att

1 curtida

Bom dia,

Sim, através das constraints você pode mandar parâmetros para dentro de um dataset.

Segue a documentação: http://tdn.totvs.com/display/fluig/Desenvolvimento+de+Datasets#DesenvolvimentodeDatasets-ConstraintsAvançadas

É possível sim, mas dentro do seu Dataset customizado você tem que tratar o parâmetro recebido. Segue exemplo abaixo: (Está a partir do comentário "AQUI VOCÊ TRATA O FILTRO")


function createDataset(fields, constraints, sortFields) {
    var empresa = "";
    var filtro  = "";
    var nulo    = null;

    var newDataset = DatasetBuilder.newDataset();

    var protheusService  = ServiceManager.getService('wsipfluig'); 
    var serviceHelper    = protheusService.getBean();
    var serviceLocator   = serviceHelper.instantiate('br.com.totvsip.wsportal_apw.WSIPFLUIGLocator');
    var service          = serviceLocator.getWSIPFLUIGSOAP();

    var sql = "SELECT ctt_custo, " +
            "        ctt_desc01, " +
            "        (TRIM(ctt_custo) || ' - ' || TRIM(ctt_desc01)) COD_DESC, " +
            "        ctt_zzapsa, " +
            "        ctt_bloq ";

    newDataset.addColumn("empresa");
    newDataset.addColumn("ccusto");
    newDataset.addColumn("descricao");
    newDataset.addColumn("cod_desc");
    newDataset.addColumn("aprovador");
    newDataset.addColumn("bloqueado");

    if(constraints != null) {
        if(constraints.length > 0) {

           for (var i = 0; i < constraints.length; i++) {
            // AQUI VOCÊ TRATA O FILTRO
                if (constraints[i].fieldName == 'empresa') {
                    empresa = constraints[i].initialValue;
                    filtro += "    FROM ctt"+empresa+"0 ";
                    filtro += "WHERE D_E_L_E_T_ = ' ' ";
                }                
                if (constraints[i].fieldName == 'ccusto' || constraints[i].fieldName == 'filtro') {
                    filtro += "AND ctt_custo LIKE '%" + constraints[i].initialValue + "%' ";
                }
                if (constraints[i].fieldName == 'descricao') {
                    filtro += "AND ctt_desc01 LIKE '%" + constraints[i].initialValue + "%' ";
                }
                if (constraints[i].fieldName == 'cod_desc') {
                    filtro += "AND (TRIM(ctt_custo) || ' - ' || TRIM(ctt_desc01)) LIKE '%" + constraints[i].initialValue + "%' ";
                }
                if (constraints[i].fieldName == 'aprovador') {
                    log.info(constraints[i].initialValue);
                    if (constraints[i].initialValue == "<> ' '") {
                        filtro += "AND ctt_zzapsa " + constraints[i].initialValue + " ";
                    } else {
                        filtro += "AND ctt_zzapsa LIKE '%" + constraints[i].initialValue + "%' ";
                    }
                }
                if (constraints[i].fieldName == 'bloqueado') {
                    filtro += "AND ctt_bloq = '" + constraints[i].initialValue + "' ";
                }
            }
            var nulo = "N";

            filtro += "ORDER BY ctt_desc01 ";
        }
    }

    sql = sql + filtro;

    sql = sql.toUpperCase();
    log.info("#### SQL GERADO");
    log.info(sql);

    try {
        if (empresa == '') {
            newDataset.addRow(new Array("[ERRO] => Informe a Empresa para fazer a consulta"));
        } else {

            var x = service.EXECQUERY(sql,empresa,"01",key);
            var z = x.getCOLSFLD().getTABLEFIELDS();

            var i = 0;
            var valor = "";


            for(i = 0;i < z.length ; i++){
               valor = x.getCOLSFLD().getTABLEFIELDS(i);

               var cols    = valor.getVALOR().getSTRING().length;
               var valCols = valor.getVALOR(); 
               var aCols   = new Array();

               aCols.push(empresa);
               for (var j = 0; j < cols; j++) {
                   aCols.push(valCols.getSTRING(j).trim());
               }

               newDataset.addRow(aCols);
               valor = "";
            } 
        }

    } catch(erro) { 
        log.error("#### =======> ERRO DATASET: " + erro);
    }

    return newDataset;
}

Obrigado Gabriel, estava faltando o tratamento da constraint no meu custom dataset.

1 curtida