You need to sign in to do that
Don't have an account?
Luciano Roberto
Get picklist text to insert record case component Lightning
Hy Folks,
I need pass text of picklist to insert a record of case by component lightning .
I need the text instead of the value, by the way, how can I pass on the text and the value?
Code
Component.cmp
<aura:attribute name="caseObj" type="case" default="{'sobjectType': 'Case',
'AccountId': '',
'MSISDN__c': '',
'Status': '',
'Origin': '' ,
'Motivo1__c': ''
}"/>
<label>Montadora</label>
<force:inputField aura:id="AccountId" value="{!v.caseObj.AccountId}"/>
</div>
<div class="form-group">
<label>MSISDN</label>
<ui:inputText class="form-control" value="{!v.caseObj.MSISDN__c}"/>
</div>
<div class="form-group">
<label>Status</label>
<force:inputField aura:id="Status" value="{!v.caseObj.Status}"/>
</div>
<div class="form-group">
<label>Origem</label>
<force:inputField aura:id="Origin" value="{!v.caseObj.Origin}"/>
</div>
<!-- PICKLIST I NEED GET TEXT OF SELECTION -->
<!-- --------------------------------------------------------------- -->
<lightning:layoutItem size="12" padding="around-small">
<lightning:select aura:id="Motivo1__c"
value="{!v.caseObj.Motivo1__c}"
name="motivo1"
label="Motivo 1"
onchange="{!c.onControllerFieldChange}">
<aura:iteration items="{!v.listMotivos1}" var="val">
<option value="{!val.MasterLabel}">{!val.DependentFieldTextPtBR__c}</option>
</aura:iteration>
</lightning:select>
</lightning:layoutItem>
----------------------------------------------------------------
Controller.js
create: function(component, event, helper) {
console.log('Create record');
var caseObj = component.get("v.caseObj");
var action = component.get("c.createRecord");
action.setParams({
caseObj : caseObj
});
------------------------------------------------------------
ClassController.apxc
@AuraEnabled
public static void createRecord (Case caseObj){
try{
System.debug('NovoCasoComponentController::createRecord::caseObj'+ caseObj);
if(caseObj != null){
caseObj.Account = null;
insert caseObj;
}
} catch (Exception ex){
}
Thanks!
I need pass text of picklist to insert a record of case by component lightning .
I need the text instead of the value, by the way, how can I pass on the text and the value?
Code
Component.cmp
<aura:attribute name="caseObj" type="case" default="{'sobjectType': 'Case',
'AccountId': '',
'MSISDN__c': '',
'Status': '',
'Origin': '' ,
'Motivo1__c': ''
}"/>
<label>Montadora</label>
<force:inputField aura:id="AccountId" value="{!v.caseObj.AccountId}"/>
</div>
<div class="form-group">
<label>MSISDN</label>
<ui:inputText class="form-control" value="{!v.caseObj.MSISDN__c}"/>
</div>
<div class="form-group">
<label>Status</label>
<force:inputField aura:id="Status" value="{!v.caseObj.Status}"/>
</div>
<div class="form-group">
<label>Origem</label>
<force:inputField aura:id="Origin" value="{!v.caseObj.Origin}"/>
</div>
<!-- PICKLIST I NEED GET TEXT OF SELECTION -->
<!-- --------------------------------------------------------------- -->
<lightning:layoutItem size="12" padding="around-small">
<lightning:select aura:id="Motivo1__c"
value="{!v.caseObj.Motivo1__c}"
name="motivo1"
label="Motivo 1"
onchange="{!c.onControllerFieldChange}">
<aura:iteration items="{!v.listMotivos1}" var="val">
<option value="{!val.MasterLabel}">{!val.DependentFieldTextPtBR__c}</option>
</aura:iteration>
</lightning:select>
</lightning:layoutItem>
----------------------------------------------------------------
Controller.js
create: function(component, event, helper) {
console.log('Create record');
var caseObj = component.get("v.caseObj");
var action = component.get("c.createRecord");
action.setParams({
caseObj : caseObj
});
------------------------------------------------------------
ClassController.apxc
@AuraEnabled
public static void createRecord (Case caseObj){
try{
System.debug('NovoCasoComponentController::createRecord::caseObj'+ caseObj);
if(caseObj != null){
caseObj.Account = null;
insert caseObj;
}
} catch (Exception ex){
}
Thanks!
But i was able to solve by creating a formula field with some conditions to get the value I wanted for each item selected in the picklist.
Not ideal, but broke the branch.
All Answers
I am not sure from where you are getting listMotivos1 but I believe it has both label/text and values like this:
{
[
{MasterLabel: 'any label', DependentFieldTextPtBR__c: 'related value'},
{MasterLabel: 'any label2', DependentFieldTextPtBR__c: 'related value2'},
{MasterLabel: 'any label3', DependentFieldTextPtBR__c: 'related value3'}
]
}
If you want DependentFieldTextPtBR__c to be saved in the system instead of MasterLabel ( ie 'related value' instead of 'any label'),
changing values in option should do that. You can put the option tag like this:
This way it will show DependentFieldTextPtBR__c to users and same value will be saved in the database. Please note that picklist values
in caseObj.Motivo1__c should match to text values you are showing otherwise we can get errors ( Restricted picklists).
Please let me know if I didn't understand your issue correctly.
Thanks.
Thanks Rohit , but i need MasterLabel because there are five dependent lists that work through it.
But to include the record, I need only the picklist text that will be stored in a text box.
Do I have to pass the text in any other way?
But i was able to solve by creating a formula field with some conditions to get the value I wanted for each item selected in the picklist.
Not ideal, but broke the branch.