function defineStructure() {
	
 	addColumn("A1_COD");
 	addColumn("A1_NREDUZ");
 	addColumn("A1_END");
 	addColumn("A1_MUN");
 	addColumn("A1_EST");
 	setKey(["A1_COD"]);
 	
 	addIndex([ "A1_COD", "A1_NREDUZ","A1_END", "A1_MUN","A1_EST"]);
}

function onSync(lastSyncDate) {
	
	log.info("Entrou na Consulta");
	var dataset = DatasetBuilder.newDataset(); 

try {
	
	//--------------------------------------------------------------------------------------------------
	var clientService = fluigAPI.getAuthorizeClientService();
	var data = {
	          companyId : ''+getValue('WKCompany')+'',
	          serviceCode : 'ConsultaClientes',
	          endpoint : '?page=1&pagesize=9000',
	          method : 'GET',
	          params : {  },
	          timeoutService: '10000'
	   }
	
	log.info("DATA");	
	log.info(data);
	
	log.info("DATA stringify");
	log.info(JSON.stringify(data));
	
	var vo = clientService.invoke(JSON.stringify(data));
	log.info(vo);
	var x = JSON.parse(vo.getResult());
	//var x = vo.getResult();
	log.info("Valor de X: " + JSON.stringify(x));
	
	for(var i in x.clientes){
		
		dataset.addOrUpdateRow(new Array(x.clientes[i].A1_COD,x.clientes[i].A1_NREDUZ,x.clientes[i].A1_END,x.clientes[i].A1_MUN,x.clientes[i].A1_EST));	
	}
	
	}catch(err){
		
		log.info(err);
	}
	
	return dataset
} 