You need to sign in to do that
Don't have an account?
Hruday
How to pull Field values of a on the Controller side
I am trying to build a quick action, when clicked, will check for the Status field. IF status != Closed, wil redirect to visualforce page. Below is my component and controller codes.
CloseCase.cmp
<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId,flexipage:availableForAllPageTypes">
<!-- This attribute saves the record ID -->
<aura:attribute name="recordId" type="String" />
<aura:attribute name="CaseObject" type="Object" />
<aura:attribute type="Object" name="record"/>
<aura:attribute name="CaseStatusValue" type = "String" /> -->
<aura:attribute name="recordLoadError" type="String"/>
<force:recordData aura:id="recordLoader"
recordId="{!v.recordId}"
fields="Name,Status"
targetFields="{!v.CaseObject}"
targetError="{!v.recordLoadError}"
targetRecord="{!v.record}"
/>
<!-- This executes a function from the controller as soon as the component is open.
This is recommended when the action only processes data and there’s no need for user interaction -->
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
</aura:component>
CloseCaseController.js
({
doInit : function(component, event, helper) {
var Caseid = component.get("v.recordId");
var CaseStatus = component.get("v.CaseObject").Status;
console.log(CaseStatus);
if(CaseStatus != "Closed"){
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
"url": "/apex/KBReviewClose?id="+Caseid+"",
"width" : "700",
"height" : "1000",
"scrollbars" : "yes"
});
urlEvent.fire();
}
else{
var resultsToast = $A.get("e.force:showToast");
resultsToast.setParams({
"title" : "Failed",
"message" : "Case is already closed",
"type" : "warning",
"duration" : "60000ms"
});
resultsToast.fire();}
}
})
On the controller side, I am trying to get the 'Status' value of the case record and redirecting to a visualforce page if status is not equal to 'Closed'.
I am getting the below error. please help.
Error while creating component for lightning component quick action [Action failed: c:LCC_Close_KB_Review_Case$controller$doInit [Cannot read property 'Status' of null]].
CloseCase.cmp
<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId,flexipage:availableForAllPageTypes">
<!-- This attribute saves the record ID -->
<aura:attribute name="recordId" type="String" />
<aura:attribute name="CaseObject" type="Object" />
<aura:attribute type="Object" name="record"/>
<aura:attribute name="CaseStatusValue" type = "String" /> -->
<aura:attribute name="recordLoadError" type="String"/>
<force:recordData aura:id="recordLoader"
recordId="{!v.recordId}"
fields="Name,Status"
targetFields="{!v.CaseObject}"
targetError="{!v.recordLoadError}"
targetRecord="{!v.record}"
/>
<!-- This executes a function from the controller as soon as the component is open.
This is recommended when the action only processes data and there’s no need for user interaction -->
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
</aura:component>
CloseCaseController.js
({
doInit : function(component, event, helper) {
var Caseid = component.get("v.recordId");
var CaseStatus = component.get("v.CaseObject").Status;
console.log(CaseStatus);
if(CaseStatus != "Closed"){
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
"url": "/apex/KBReviewClose?id="+Caseid+"",
"width" : "700",
"height" : "1000",
"scrollbars" : "yes"
});
urlEvent.fire();
}
else{
var resultsToast = $A.get("e.force:showToast");
resultsToast.setParams({
"title" : "Failed",
"message" : "Case is already closed",
"type" : "warning",
"duration" : "60000ms"
});
resultsToast.fire();}
}
})
On the controller side, I am trying to get the 'Status' value of the case record and redirecting to a visualforce page if status is not equal to 'Closed'.
I am getting the below error. please help.
Error while creating component for lightning component quick action [Action failed: c:LCC_Close_KB_Review_Case$controller$doInit [Cannot read property 'Status' of null]].
component:
Controller:
All Answers
Remove <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
and update the force:recordData to Hope this helps. Please mark it as a best answer if it does.
Thanks for the help. however, i still get CaseStatus = 'null' at CaseStatus variable in the controller.
component
<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId,flexipage:availableForAllPageTypes">
<aura:attribute name="recordId" type="String" />
<aura:attribute name="CaseObject" type="Case" />
<aura:attribute type="Object" name="record"/>
<aura:attribute name="recordLoadError" type="String"/>
<force:recordData aura:id="record"
recordId="{!v.recordId}"
fields="Name,Status"
targetFields="{!v.CaseObject}"
targetError="{!v.recordLoadError}"
targetRecord="{!v.record}"
recordUpdated="{!c.doInit}"
/>
</aura:component>
Controller
({
doInit : function(component, event, helper) {
var Caseid = component.get("v.recordId");
var CaseStatus = component.get("{!v.CaseObject.Status}");
console.log(CaseStatus);
if(CaseStatus != "Closed"){
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
"url": "/apex/KBReviewClose?id="+Caseid+"",
"width" : "700",
"height" : "1000",
"scrollbars" : "yes"
});
urlEvent.fire();
}
else{
var resultsToast = $A.get("e.force:showToast");
resultsToast.setParams({
"title" : "Failed",
"message" : "Case is already closed",
"type" : "warning",
"duration" : "60000ms"
});
resultsToast.fire();}
}
})
I am sure there is some syntax error here, but unable to get through it.Can you also please help me how to assign it to CaseStatus variable in the controller?
Thanks
component.
<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId,flexipage:availableForAllPageTypes">
<!-- This attribute saves the record ID -->
<aura:attribute name="recordId" type="String" />
<aura:attribute name="CaseObject" type="Object" />
<aura:attribute name="recordLoadError" type="String"/>
<force:recordData aura:id="record"
recordId="{!v.recordId}"
fields="Name,Status"
targetFields="{!v.CaseObject}"
targetError="{!v.recordLoadError}"
targetRecord="{!v.record}"
recordUpdated="{!c.doInit}"
/>
</aura:component>
controller.
({
doInit : function(component, event, helper) {
var Caseid = component.get("v.recordId");
var CaseStatus = component.get("v.CaseObject").Status;
console.log(CaseStatus);
if(CaseStatus != "Closed"){
var urlEvent = $A.get("e.force:navigateToURL");
urlEvent.setParams({
"url": "/apex/KBReviewClose?id="+Caseid+"",
"width" : "700",
"height" : "1000",
"scrollbars" : "yes"
});
urlEvent.fire();
}
else{
var resultsToast = $A.get("e.force:showToast");
resultsToast.setParams({
"title" : "Failed",
"message" : "Case is already closed",
"type" : "warning",
"duration" : "60000ms"
});
resultsToast.fire();}
}
})
Please let me know what am I missing. Appreciate your help.
Which means that you only have to remove the 'Name' field from the fields List record data as it does not exist on Case. Hope this helps. Please mark it as a best answer if it does.
Hi Rushikesh,
I appreciate your help.I have removed 'Name' field from fields, With this, i could fix the syntax error, But still iam unable to pull the status field value onto the controller side. Please see the screenshot.Not sure what I am missing.
The requirement here is, when this component is clicked, a visualforce page should be opened if the 'Status'!= Closed.
component:
Controller: