I have a requirement to create a new To Do record with autopopulating the Ownerid field to the logged in user. I have created a lightning component and trying to assign the returntype value from apex controller to the aura attribute. The value is being assigned to the aura attribute but not to the lookup field.here is my code
Apex controller
public class CreateMeetingController {
@AuraEnabled
public static String getUserId(){
return UserInfo.getUserId();
}
}
lightning component
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" controller="Controller" >
<aura:attribute name="isOpen" type="boolean" default="true" />
<aura:attribute name="newToDo" type="Task" />
<aura:attribute name="duedate" type="DateTime" />
<aura:attribute name="subject" type="String" />
<aura:attribute name="assignTo" type="String" />
<aura:attribute name="relatedTo" type="String" />
<aura:attribute name="name" type="String" />
<aura:attribute name="status" type="String" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<div class="slds-m-around--xx-large">
<aura:if isTrue="{!v.isOpen}">
<div role="dialog" tabindex="-1" aria-labelledby="header99" class="slds-modal slds-fade-in-open ">
<div class="slds-modal__container">
<div class="slds-modal__header">
<button class="slds-button slds-modal__close slds-button--icon-inverse" title="Close" onclick="{!c.closeModel}">
X
<span class="slds-assistive-text">Close</span>
</button>
<h2 id="header99" class="slds-text-heading--medium">Create To Do</h2>
</div>
<div class="slds-modal__content slds-p-around--medium">
<div class="slds-form--stacked">
<lightning:input aura:id="subjectInput" label="Subject" value="{! v.subject }" class="form-control"
required="true"/>
<ui:inputDate aura:id="iddueDate" label="Due Date" class="form-control"
value="{!v.duedate}" displayDatePicker="true" required="true"/>
<div class="form-group">
<c:inputLookup value="{!v.name}"
label="Name"
pluralLabel="Contacts"
sObjectAPIName="Contact"
instanceId="relatedToContact"
iconName="standard:contact"
listIconClass="slds-icon-standard-contact"
class="slds-size--1-of-1" />
</div>
<div class="form-group">
<c:inputLookup value="{!v.relatedTo}"
label="Related to Account"
pluralLabel="Account"
sObjectAPIName="Account"
iconName="standard:account"
listIconClass="slds-icon-standard-account"
class="slds-size--1-of-1" />
</div>
<div class="form-group">
<c:inputLookup value="{!v.assignTo}"
instanceId="UserId"
label="Assigned To"
pluralLabel="Users"
sObjectAPIName="User"
iconName="standard:user"
listIconClass="slds-icon-standard-user"
class="slds-size--1-of-1" />
</div>
<div class="form-group">
<ui:inputSelect label="Status " class="dynamic" aura:id="InputSelectDynamic" value="{!v.status}" />
</div>
</div>
</div>
<!--###### MODAL BOX FOOTER Part Start From Here ######-->
<div class="slds-modal__footer">
<button class="slds-button slds-button--neutral" onclick="{!c.saveRecord}">Save</button>
<button class="slds-button slds-button--neutral" onclick="{!c.closeModel}">Cancel</button>
</div>
</div>
</div>
<div class="slds-backdrop slds-backdrop--open"></div>
<!--###### MODAL BOX Part END Here ######-->
</aura:if>
</div>
</aura:component>
Controller.js
({
doInit : function(component, event, helper) {
component.set("v.isOpen", true);
var action= component.get("c.getUserId");
action.setCallback(this, function(response) {
var state = response.getState();
console.log('state-------->'+state);
console.log('component.isValid()-------->'+component.isValid());
if(component.isValid() && state === "SUCCESS"){
var assignTo = response.getReturnValue();
console.log('assignTo------->'+assignTo);
component.set("v.assignTo",assignTo);
var userid= component.get("v.assignTo");
console.log('userid-------------<'+userid);
}
});
$A.enqueueAction(action);
}
})
Debug log for controller.js
state-------->SUCCESS
component.isValid()-------->true
assignTo------->0055B000000NSeLQAW
userid-------------<0055B000000NSeLQAW
If you see from debug log the value is assigned to the attribute (userid) but in component its not prepopulating the value for the field with InstanceId: 'UserId'.