Um exemplo de dataset:
function defineStructure() {
addColumn('FILIAL');
addColumn('GW1_NRDC');
addColumn('SERIE');
addColumn('GW1_CDDEST');
addColumn('GU3_NMEMIT');
addColumn('GW1_DANFE');
addColumn('F2_TRANSP');
addColumn('GW1_NRROM');
}
function onSync(lastSyncDate) {
}
function createDataset(fields, constraints, sortFields) {
var dataset = DatasetBuilder.newDataset();
var sqlStr = " SELECT GW1FILIAL as FILIAL, "+
" RTRIM(GW1_NRDC) GW1_NRDC, RTRIM(GW1_SERDC) AS SERIE, "+
" GW1_CDDEST, CLIENTE.GU3_NMEMIT, RTRIM(GW1_DANFE) GW1_DANFE, "+
" TRANSP.GU3_CDTERP F2_TRANSP, "+
" RTRIM(GW1_NRROM) GW1_NRROM "+
" FROM GW1030 GW1 (NOLOCK) "+
" INNER JOIN GU3030 CLIENTE (NOLOCK) ON CLIENTE.GU3_CDEMIT = GW1_CDDEST AND CLIENTE.D_E_L_E_T = '' "+
" INNER JOIN GWU030 TRECHO (NOLOCK) ON GW1.GW1NRDC = TRECHO.GWU_NRDC AND GW1_SERDC = TRECHO.GWU_SERDC AND TRECHO.D_E_L_E_T = '' "+
" INNER JOIN GU3030 TRANSP (NOLOCK) ON TRANSP.GU3CDEMIT = TRECHO.GWU_CDTRP AND TRANSP.D_E_L_E_T = '' "+
" INNER JOIN SF2030 SF2 (NOLOCK) ON F2FILIAL = GW1_FILIAL AND GW1_NRDC = F2_DOC AND GW1_SERDC = F2_SERIE AND SF2.D_E_L_E_T ='' AND F2CHVNFE = GW1_DANFE "+
" WHERE GW1.D_E_L_E_T = '' "+
" AND GW1_DANFE <> '' AND GW1_SIT <> '5' AND GW1_SIT <> '7'";
if (constraints != null) {
for (var i = 0; i < constraints.length; i++) {
if (constraints[i].fieldName == "F2_TRANSP") { //codTransportadora
sqlStr = sqlStr + " AND F2_TRANSP = '" +constraints[i].initialValue + "'";
} else if (constraints[i].fieldName == "GW1_DANFE") {
sqlStr = sqlStr + " AND GW1_DANFE LIKE '%" +constraints[i].initialValue + "%'";
} else if (constraints[i].fieldName == "GW1_CDDEST") { //cliente
sqlStr = sqlStr + " AND GW1_CDDEST = '" +constraints[i].initialValue + "'";
} else if (constraints[i].fieldName == "GW1_NRDC") { //nf
sqlStr = sqlStr + " AND GW1_NRDC <> '" +constraints[i].initialValue + "'";
}
}
}
var cst1 = DatasetFactory.createConstraint("SQL", sqlStr , sqlStr, ConstraintType.MUST);
var cst2 = DatasetFactory.createConstraint("dataSource", 'PROTT' , 'PROTT', ConstraintType.MUST);
var filtro2 = new Array(cst1, cst2);
dataset = DatasetFactory.getDataset("dsSQL", null, filtro2, null);
return dataset;