0

I'm trying to set a boolean field to False when a lightning component on the case object is clicked.

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);
   }
})

I'm pretty new to lightning components and have been playing around for a while. I'm specifically getting the following error : Uncaught Action failed: c:UnEscalate$controller$unescalate [FALSE is not defined] Any help would be greatly appreciated.

3
  • 1
    Did you try caseObject.Admin_Escalation__c = false; ? Commented Jan 9, 2020 at 17:11
  • Hi @MartinLezer I did indeed, I get "Uncaught Unable to find action 'Admin_Escalation__c' on the controller of c:UnEscalate" on updating it to : caseObject.Admin_Escalation__c = false; Commented Jan 9, 2020 at 17:36
  • Can you please post apex controller code as well? Commented Jan 10, 2020 at 9:03

2 Answers 2

1

Javascript doesn't understand uppercase FALSE or TRUE. It should be in small case false and true.

Setting caseObject.Admin_Escalation__c = false; should work.

2
  • Yeah I did try that, however, still getting an error albeit slightly different ""Uncaught Unable to find action 'Admin_Escalation__c' on the controller of c:UnEscalate" on updating it to : caseObject.Admin_Escalation__c = false;" Commented Jan 9, 2020 at 18:24
  • Does the user has necessary permission of that field? Commented Jan 9, 2020 at 19:42
0

Managed to get it working.

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;
}

}

<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'}"/>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .