0

How can I read a task object properties in a lightning controller. Because var a=component.get("v.Task").Status; returns error which is Uncaught

Error in $A.getCallback() [Cannot read property 'Status' of null].

Can anyone tells me if the Task object is supported by Lightning UI? Thank you this is my .cmp

<aura:component controller="JSMUserInfoService" implements="force:lightningQuickActionWithoutHeader,force:hasRecordId" access="global">
  <aura:attribute name="user" type="JSMUserInfo" />
    <div style="height: 6rem;">
        <div role="status" class="slds-spinner slds-spinner_large slds-spinner_brand">
            <span class="slds-assistive-text">Loading</span>
            <div class="slds-spinner__dot-a"></div>
            <div class="slds-spinner__dot-b"></div>
        </div>
    </div>
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="Task" type="Object"/>
    <force:recordData aura:id="recordLoader"
                      layoutType="FULL"
                      recordId="{!v.recordId}"
                      targetFields="{!v.Task}"
                      recordUpdated="{!c.doInit}"
    />

</aura:component>

And this is my controller:

({
  doInit : function(component, event, helper) {
    var getProfileInfo = component.get("c.getProfileInfo"); 

     getProfileInfo.setCallback(this, function(response) {
          var state = response.getState();
         alert(state);
      if(state == "SUCCESS" && component.isValid()){
        console.log("success");   
          alert('a');
          var result = response.getReturnValue();
        console.log(result);
          var a=component.get("v.Task").Status;
          alert(a);
        if(a!= "Ouvert" ||( result.Name != "System Administrator" && result.Name != "Administrateur système")){
          alert("aaaaa");
        } else {
          var CreateTask = component.get('c.CreateTask'); 
          CreateTask.setCallback(this, function(response){
          var state = response.getState(); // get the response state
          if(state == 'SUCCESS') {
            var res = response.getReturnValue();
            res.Id = component.get("v.Task").Id;
            var getUserInfo = component.get('c.getUserInfo'); 
            getUserInfo.setCallback(this, function(response){
              var state = response.getState();
              if(state == 'SUCCESS') {
                var info = response.getReturnValue();
                res.OwnerId = info.Id;
                var updateTask = component.get('c.updateTask');
                updateTask.setParams({
                  "task" : res
                });
                updateTask.setCallback(this, function(response){
                  var state = response.getState();
                  if(state == 'SUCCESS') {
                    window.location.reload();
                  }
                });
                $A.enqueueAction(updateTask);
              }
            });
            $A.enqueueAction(getUserInfo);
          }

          });
          $A.enqueueAction(CreateTask); 
        }
      }else{
          console.error("failresponse.getError()[0].message"); 
      }        
   });
  $A.enqueueAction(getProfileInfo);  
}
})
  • 1
    Please edit your question to add more context. There are specific Lightning components that do not support Task. – David Reed Jun 26 '19 at 11:28
  • I edited my post, thank you David Reed – SF trainer Jun 26 '19 at 13:15
1

<force:recordData> does not support Task and Event.

The documentation on the component refers us to the UI API documentation for a list of supported objects. That list is here. Task and Event aren't listed and are unsupported.

This is in common with other base Lightning components, like <lightning:recordViewForm>, where it's explicitly stated that

This component doesn't support all Salesforce standard objects. For example, the Event and Task objects are not supported.

You'll have to use Apex to access these records, unfortunately.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.