+ Start a Discussion
Oliver Westlake-SimmOliver Westlake-Simm 

lightning component to update field

I'm trying to create a lightning component that updates a boolean field on the case object, I've been playing around with it for a few days and can't work it out. I'm getting an error : Uncaught Action failed: c:UnEscalate$controller$unescalate [FALSE is not defined]
Using the following to trying and achieve the desired outcome. 

Component
<aura:component controller="UnescalateController" implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
	  <aura:at>tribute name="CaseObj" type="Case" default="{ 'sobjectType' : 'case'}"/>
      <lightning:button label="Unescalate" onclick="{! c.unescalate}"/>
</aura:component
JS Controller
({
  unescalate : function(component, event, helper) {
      
      var caseObject = component.get("v.CaseObj");
        caseObject.Admin_Escalation__c = FALSE;
       
       
      var action = component.get("c.updateAdmin_Escalation__c");
          action.setParams({
            obj: caseObject,
            oId : component.get("v.recordId")  
        });
      // set call back 
        action.setCallback(this, function(response) {
            
            var state = response.getState();
            if (state === "SUCCESS") {
                alert('This case has been unescalated!');
                $A.get('e.force:refreshView').fire();
            }
             else if (state === "INCOMPLETE") {
                alert("From server: " + response.getReturnValue());
            } else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        console.log("Error message: " + errors[0].message);
                    }
                } else {
                    console.log("Unknown error");
                }
            }
        });
        // enqueue the action
        $A.enqueueAction(action);
   }
})
Apex Controller
 
public class UnescalateController {
 @AuraEnabled 
    public static void updateStatus(case obj,String oId){
        system.debug('obj' + obj);
        case cc = obj;
        cc.Id = oId;
        update cc;
    }
}


 
Best Answer chosen by Oliver Westlake-Simm
Oliver Westlake-SimmOliver Westlake-Simm
I managed to solve it...was way off. 
 
<aura:component controller="UnescalateCaseController" implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,flexipage:availableForRecordHome,force:hasRecordId" access="global">
    <aura:handler name="init" value="{!this}" action="{!c.init}"/>
    <aura:attribute name="case" type="Case"/>
    <ui:button aura:id="unescalatebtn" class="slds-button slds-button--brand" label="Unescalate" press="{!c.onclick}" disabled="{!v.case.Admin_Escalation__c == false ? 'true' : 'false'}"/>
</aura:component>
 
public class UnescalateCaseController {
    @AuraEnabled
    public static Case getCase(Id recordId){
        Case caseRec = [SELECT Id, Admin_Escalation__c FROM Case WHERE id=:recordId];
        return caseRec;
    }
    
    @AuraEnabled
    public static Case saveCase(Case caseRec){

		caseRec.Admin_Escalation__c = FALSE;

        update caseRec;
        return caseRec;
    }
}

What i'm encountering now, is that this function can only be used once. 

All Answers

Nayana KNayana K
Javascript is case sensitivie. It doesn't understand that FALSE and false are same.
Please update the line:

caseObject.Admin_Escalation__c = false;
Oliver Westlake-SimmOliver Westlake-Simm
I managed to solve it...was way off. 
 
<aura:component controller="UnescalateCaseController" implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,flexipage:availableForRecordHome,force:hasRecordId" access="global">
    <aura:handler name="init" value="{!this}" action="{!c.init}"/>
    <aura:attribute name="case" type="Case"/>
    <ui:button aura:id="unescalatebtn" class="slds-button slds-button--brand" label="Unescalate" press="{!c.onclick}" disabled="{!v.case.Admin_Escalation__c == false ? 'true' : 'false'}"/>
</aura:component>
 
public class UnescalateCaseController {
    @AuraEnabled
    public static Case getCase(Id recordId){
        Case caseRec = [SELECT Id, Admin_Escalation__c FROM Case WHERE id=:recordId];
        return caseRec;
    }
    
    @AuraEnabled
    public static Case saveCase(Case caseRec){

		caseRec.Admin_Escalation__c = FALSE;

        update caseRec;
        return caseRec;
    }
}

What i'm encountering now, is that this function can only be used once. 
This was selected as the best answer