function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Thiago Barbosa 1Thiago Barbosa 1 

[Unexpected token u in JSON at position 0]

({
	onSelectTipoCaso : function(component, event, helper){
        var action = component.get("c.retornaOpcoesTipoCasoLightning");
        
        
        action.setCallback(this,function(response){
           var state = response.getState();
            console.log('State' + state);
            
            
            if(state === "SUCCESS"){
               
                             
                var optionsList = [];
                var objreturn= response.getReturnValue();
                for (var key in objreturn['lTipoAcaoApresentacao']) {
                    optionsList.push({value: key, label: objreturn['lTipoAcaoApresentacao'][key]  ,selected: response.getReturnValue()['lTiposApresentacao'] == key });        
                };
                console.log("Option" + JSON.stringify(optionsList));
                
                component.set("v.lstTiposApresentacao", optionsList);
                component.set('v.acaoTipos' , response.getReturnValue()['lTiposApresentacao']);
                
            }else if (state === 'ERROR') {
                var errors = response.getError();
                if (errors[0] && errors[0].message) {
                    helper.showToast('Erro', errors[0].message, 'error', 'dismissible');
                }
            }
                else {
                    helper.showToast('Erro', 'Erro desconhecido', 'error', 'dismissible');
                }
        });
        $A.enqueueAction(action);
    },
    
    onExport : function(component, event, helper){
        
        var mapExportar = component.get('v.mapExportar');
        mapExportar["dataInicio"] = component.get("v.nomeCase").Data_Inicio__c;
        mapExportar["dataFinal"] = component.get("v.nomeCase").Data_Fim__c;
        mapExportar["lAtualizar"] = component.get('v.lAtualiza');
        mapExportar["lFltTipoCaso"] = JSON.parse(component.find("selectItemCaso").get("v.value"))[0].value;
        mapExportar["lFltStatusCaso"] = component.get('v.lFltStatusCaso');
        mapExportar["num_atc"] = component.get('v.num_atc');
        mapExportar["lSysSoqlLimit"]  = component.get('v.sql');
        
        component.set('v.mapExportar', mapExportar);
        
        for(var key in mapExportar){  
            console.log('Map' + mapExportar["dataInicio"]);
            var isTipoData = (key == "dataInicio" || key == "dataFinal");
            var isDateEmpty = (mapExportar['dataInicio'] == '' || mapExportar['dataInicio'] ==  null) ||
                (mapExportar['dataFinal'] == '' || mapExportar['dataFinal'] == null);
            var isDateIniMaiorFim = (mapExportar['dataInicio'] > mapExportar['dataFinal']);
            
            if((isTipoData) && (isDateEmpty) || (isDateIniMaiorFim))
				helper.showToast('Erro', 'Data não preenchida ou Data de inicio maior que a data fim!', 'error');                
        
        }

        var action = component.get("c.botaoExportarNov		o");
        
        
        
        
        action.setParams({  
            btnExportar : mapExportar
        }); 
        
        action.setCallback(this, function(response){
           	var state = response.getState(); 
            
            if(state === "SUCCESS"){
					var returnValue = JSON.stringify(response.getReturnValue()['lSelect']);
            		var errors = JSON.stringify(response.getReturnValue()['Errors']);
                	console.log('Erros' + JSON.stringify(errors));
            		console.log('ReturnValue' + JSON.stringify(returnValue));
                	var retornoMapa = JSON.parse(returnValue);
                	console.log('Retorno Mapa' + retornoMapa); 
                
               
            
            
            }else if (state === 'ERROR') {
                var errors = response.getError();
                if (errors[0] && errors[0].message) {
                    helper.showToast('Erro', errors[0].message, 'error', 'dismissible');
                }
            }
                else {
                    helper.showToast('Erro', 'Erro desconhecido', 'error', 'dismissible');
                }
        });
        $A.enqueueAction(action);

    },
    
    
    showToast: function (title, message, type, mode) {
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            "title": title,
            "mode": mode,
            "type": type,
            "message": message,
            "duration": 10000
        });
        toastEvent.fire();
    },
})

 
Alain CabonAlain Cabon
What is the result of this console.log ?
 
if(state === "SUCCESS"){
         console.log('ReturnValue' + JSON.stringify(returnValue));

[Unexpected token u in JSON at position 0] = probably a problem during a parsing

 mapExportar["lFltTipoCaso"] =JSON.parse(component.find("selectItemCaso").get("v.value"))[0].value;
 var retornoMapa = JSON.parse(returnValue);