You need to sign in to do that
Don't have an account?
Afzaal Hassan
Retrieve Account name from search results in a lightning component
Hello
I am 95% done with writing a Lightning Component. What this app does is when a user types in a phone or name, it lists all the contact records associated with the search result. On of the columns is the account name associated with the contact. It also displays a radio button that you need to select. The only thing I have left to do is the following(and I am struggling to get it working):
If the account name starts with a P and a number, so P0232 - Greenwood, then I dont need to select the radio button. Currently, i have an error message popup when its not selected, which should only happen if the name was just Greenwood, for example. Not sure what to put in the conditional to make this work. Here is my code:
Component:
<div style="font-size: 20px">Customer Information</div>
<table>
<tr style="width: 100%;">
<td>
First Name: <lightning:input name="sFirstName" value="{!v.sFirst}"/>
</td>
<td>
Last Name: <lightning:input name="sLastName" value="{!v.sLast}"/>
</td>
<td>
Phone Number: <lightning:input name="sPhone" value="{!v.ani}"/>
</td>
<td style="vertical-align:bottom;">
<lightning:button label="Search" onclick="{!c.doConSearch}" />
</td>
</tr>
</table>
<br />
<aura:if isTrue="{!v.hasContactResults}">
<table>
<thead>
<th>First Name</th>
<th>Last Name</th>
<th>Phone</th>
<th>Mobile</th>
<th>Email</th>
<th>Current Account</th>
<th>City</th>
<th>State</th>
<th>Use This Contact</th>
</thead>
<aura:iteration items="{!v.contacts}" var="con">
<tr>
<td>{!con.FirstName}</td>
<td>{!con.LastName}</td>
<td>{!con.Phone}</td>
<td>{!con.MobilePhone}</td>
<td>{!con.Email}</td>
<td>{!con.Account.Name}</td>
<td>{!con.MailingCity}</td>
<td>{!con.MailingState}</td>
<td><ui:inputRadio name="cons" label="{!con.Id}" labelClass="invis" change="{!c.onRadio}" /></td>
</tr>
</aura:iteration>
</table>
</aura:if>
Here is the Controller:
doConSearch : function(component, event, helper) {
helper.searchContacts(component);
component.set("v.selectedCon", "");
helper.searchCases(component);
if(!component.get("v.showAct")){
var a = component.get('c.getCallQueue');
$A.enqueueAction(a);
}
},
createCase : function(component, event, helper) {
component.set("v.hasErrors", false);
component.set("v.errors", "");
var studio = component.get("v.selectedCon");
if(component.get("v.selectedStudio") || component.get("v.selectedOpp") || studio.Account.Name.contains('????')) {
if(component.get("v.selectedCon") || (component.get("v.sFirst") && component.get("v.sLast") && component.get("v.ani"))){
helper.createNewCase(component);
} else {
component.set("v.hasErrors", true);
component.set("v.errors", "Please select a Contact or enter a first name, last name, and phone");
}
} else {
component.set("v.hasErrors", true);
component.set("v.errors", "Please select a studio or opportunity");
}
},
onRadio: function(cmp, evt, helper) {
var selected = evt.getSource().get("v.label");
cmp.set("v.selectedCon", selected);
helper.searchCases(cmp);
},
selectStudio: function(cmp, evt, helper) {
var selected = evt.getSource().get("v.label");
cmp.set("v.selectedStudio", selected);
},
The if statement where you see the bold item is where the logic needs to go. I dont have the right syntax for the item in bold. Any help wuld be appreciated. Thanks
I am 95% done with writing a Lightning Component. What this app does is when a user types in a phone or name, it lists all the contact records associated with the search result. On of the columns is the account name associated with the contact. It also displays a radio button that you need to select. The only thing I have left to do is the following(and I am struggling to get it working):
If the account name starts with a P and a number, so P0232 - Greenwood, then I dont need to select the radio button. Currently, i have an error message popup when its not selected, which should only happen if the name was just Greenwood, for example. Not sure what to put in the conditional to make this work. Here is my code:
Component:
<div style="font-size: 20px">Customer Information</div>
<table>
<tr style="width: 100%;">
<td>
First Name: <lightning:input name="sFirstName" value="{!v.sFirst}"/>
</td>
<td>
Last Name: <lightning:input name="sLastName" value="{!v.sLast}"/>
</td>
<td>
Phone Number: <lightning:input name="sPhone" value="{!v.ani}"/>
</td>
<td style="vertical-align:bottom;">
<lightning:button label="Search" onclick="{!c.doConSearch}" />
</td>
</tr>
</table>
<br />
<aura:if isTrue="{!v.hasContactResults}">
<table>
<thead>
<th>First Name</th>
<th>Last Name</th>
<th>Phone</th>
<th>Mobile</th>
<th>Email</th>
<th>Current Account</th>
<th>City</th>
<th>State</th>
<th>Use This Contact</th>
</thead>
<aura:iteration items="{!v.contacts}" var="con">
<tr>
<td>{!con.FirstName}</td>
<td>{!con.LastName}</td>
<td>{!con.Phone}</td>
<td>{!con.MobilePhone}</td>
<td>{!con.Email}</td>
<td>{!con.Account.Name}</td>
<td>{!con.MailingCity}</td>
<td>{!con.MailingState}</td>
<td><ui:inputRadio name="cons" label="{!con.Id}" labelClass="invis" change="{!c.onRadio}" /></td>
</tr>
</aura:iteration>
</table>
</aura:if>
Here is the Controller:
doConSearch : function(component, event, helper) {
helper.searchContacts(component);
component.set("v.selectedCon", "");
helper.searchCases(component);
if(!component.get("v.showAct")){
var a = component.get('c.getCallQueue');
$A.enqueueAction(a);
}
},
createCase : function(component, event, helper) {
component.set("v.hasErrors", false);
component.set("v.errors", "");
var studio = component.get("v.selectedCon");
if(component.get("v.selectedStudio") || component.get("v.selectedOpp") || studio.Account.Name.contains('????')) {
if(component.get("v.selectedCon") || (component.get("v.sFirst") && component.get("v.sLast") && component.get("v.ani"))){
helper.createNewCase(component);
} else {
component.set("v.hasErrors", true);
component.set("v.errors", "Please select a Contact or enter a first name, last name, and phone");
}
} else {
component.set("v.hasErrors", true);
component.set("v.errors", "Please select a studio or opportunity");
}
},
onRadio: function(cmp, evt, helper) {
var selected = evt.getSource().get("v.label");
cmp.set("v.selectedCon", selected);
helper.searchCases(cmp);
},
selectStudio: function(cmp, evt, helper) {
var selected = evt.getSource().get("v.label");
cmp.set("v.selectedStudio", selected);
},
The if statement where you see the bold item is where the logic needs to go. I dont have the right syntax for the item in bold. Any help wuld be appreciated. Thanks
You could use a regex :
Let me know if it helped you.
Have a good day,
Valentin