You need to sign in to do that
Don't have an account?
Jonathan Wolff 7
Link the columns in Task component to the displayed Task
Hello, I build an Task component. I want the link on the subject to lead to the task. I only achived to show the ID, but it doesnt lead to the task. In addition I would like to change it, that only my tasks are shown instead of all.
Could you look over my code and tell me how to fix this problem?
<aura:component controller="TaskController" implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId" >
<aura:attribute name="recordId" type="Id" />
<aura:attribute name="newTask" type="Task" default="{'sobjectType':'Task'}"/>
<aura:attribute name="tasks" type="Task[]"/>
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
<aura:attribute name="mycolumns" type="List"/>
<lightning:card iconName="standard:task" title="Tasks">
<div class="slds-card__body slds-card__body_inner">
</div>
<div>
<aura:if isTrue="{!not(empty(v.tasks))}">
<lightning:datatable data="{!v.tasks }"
columns="{!v.mycolumns }"
keyField="Id"
hideCheckboxColumn="true"/>
<aura:set attribute="else">
<div Style="text-align : center"> " There are no Tasks currently "
</div>
</aura:set>
</aura:if>
</div>
</lightning:card>
</aura:component>
Controller:
({
doInit: function(component, event, helper) {
component.set('v.mycolumns', [
{label: 'Id', fieldName: 'Id', type: 'url',
typeAttributes: {label: { fieldName: 'Id' }, target: '_blank'}},
{label: 'Subject', fieldName: 'Id', type: 'url',
typeAttributes: {label: { fieldName: 'Subject' }, target: '_blank'}},
{label: 'Activity Date', fieldName: 'ActivityDate', type: 'text'},
]);
var action = component.get("c.loadTasks");
var whatId = component.get("v.recordId");
action.setParams({
"recordId":whatId
});
action.setCallback(this, function(response){
var state = response.getState();
if (state === "SUCCESS") {
var records =response.getReturnValue();
records.forEach(function(record){
record.Subject= record.Subject;
record.ActivityDate= record.ActivityDate;
});
component.set("v.tasks", records);
}
});
$A.enqueueAction(action);
},
createNewTask : function(component, event, helper) {
var action = component.get("c.saveTask");
var newTask = component.get("v.newTask");
action.setParams({
"task": newTask
});
action.setCallback(this,function(response){
var state = response.getState();
if(component.isValid() && state === "SUCCESS"){
var items = component.get("v.tasks");
items.push(response.getReturnValue());
component.set("v.tasks",items);
}
else{
console.log("Failed with state "+state);
}
});
$A.enqueueAction(action);
}
})
Apex:
public with sharing class TaskController {
@AuraEnabled
public static List<Task> loadTasks(Id recordId){
return[SELECT Subject, ActivityDate FROM Task WHERE WhatId=:recordId And ActivityDate>= TODAY AND ActivityDate <= Next_N_Days:3];
}
@AuraEnabled
public static Task saveTask(Task task){
upsert task;
return task;
}
}
Could you look over my code and tell me how to fix this problem?
<aura:component controller="TaskController" implements="force:appHostable,flexipage:availableForAllPageTypes,force:hasRecordId" >
<aura:attribute name="recordId" type="Id" />
<aura:attribute name="newTask" type="Task" default="{'sobjectType':'Task'}"/>
<aura:attribute name="tasks" type="Task[]"/>
<aura:handler name="init" action="{!c.doInit}" value="{!this}"/>
<aura:attribute name="mycolumns" type="List"/>
<lightning:card iconName="standard:task" title="Tasks">
<div class="slds-card__body slds-card__body_inner">
</div>
<div>
<aura:if isTrue="{!not(empty(v.tasks))}">
<lightning:datatable data="{!v.tasks }"
columns="{!v.mycolumns }"
keyField="Id"
hideCheckboxColumn="true"/>
<aura:set attribute="else">
<div Style="text-align : center"> " There are no Tasks currently "
</div>
</aura:set>
</aura:if>
</div>
</lightning:card>
</aura:component>
Controller:
({
doInit: function(component, event, helper) {
component.set('v.mycolumns', [
{label: 'Id', fieldName: 'Id', type: 'url',
typeAttributes: {label: { fieldName: 'Id' }, target: '_blank'}},
{label: 'Subject', fieldName: 'Id', type: 'url',
typeAttributes: {label: { fieldName: 'Subject' }, target: '_blank'}},
{label: 'Activity Date', fieldName: 'ActivityDate', type: 'text'},
]);
var action = component.get("c.loadTasks");
var whatId = component.get("v.recordId");
action.setParams({
"recordId":whatId
});
action.setCallback(this, function(response){
var state = response.getState();
if (state === "SUCCESS") {
var records =response.getReturnValue();
records.forEach(function(record){
record.Subject= record.Subject;
record.ActivityDate= record.ActivityDate;
});
component.set("v.tasks", records);
}
});
$A.enqueueAction(action);
},
createNewTask : function(component, event, helper) {
var action = component.get("c.saveTask");
var newTask = component.get("v.newTask");
action.setParams({
"task": newTask
});
action.setCallback(this,function(response){
var state = response.getState();
if(component.isValid() && state === "SUCCESS"){
var items = component.get("v.tasks");
items.push(response.getReturnValue());
component.set("v.tasks",items);
}
else{
console.log("Failed with state "+state);
}
});
$A.enqueueAction(action);
}
})
Apex:
public with sharing class TaskController {
@AuraEnabled
public static List<Task> loadTasks(Id recordId){
return[SELECT Subject, ActivityDate FROM Task WHERE WhatId=:recordId And ActivityDate>= TODAY AND ActivityDate <= Next_N_Days:3];
}
@AuraEnabled
public static Task saveTask(Task task){
upsert task;
return task;
}
}
I've Made Some Changes in Your js.
Please Mark it As best Answer if it Helps.
Thank You!
All Answers
I've Made Some Changes in Your js.
Please Mark it As best Answer if it Helps.
Thank You!
Copy Paste the Changes In Apec Class
Please Like The Answer if it Helps.
Thank You!
string userId = UserInfo.getUserId();
I got an error when I added it in apex class
Thank you! :D
Please Like The Answer if it Helps.
Thank You!