Hi All,
I created a lookup for a Email string control in sales table form to get all the emails related to a particular customer based on delivery or invoice adrdress when I open a salesorder(Using Event handler).
In the lookup I am able to get the all the mail id’s related to particular customer from logistics postal address.
I also wrote display method to get the primary mail Id when I open the salesOrder
But I am unable to use both of them same time
I want to create a lookup where customer able select and when not selecting it should automatically show the primary Mail id when selected it should show the selected one.Is it possible. Please guide me
Below are the codes I have written.
public LogisticsLocationRecId tecDeliveryLocation()
{
return LogisticsPostalAddress::getLocation(this.DeliveryPostalAddress);
}
display Email deliveryEmail()
{
Email deliveryemail;
LogisticsLocationRecId locationRecId;
LogisticsLocation locationChild;
LogisticsElectronicAddress logisticsElectronicAddress;
LogisticsLocation Location_Inv = LogisticsLocationDefault::findSimpleDefault(CustTable::find(this.InvoiceAccount), LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Invoice));
// See if a phone number associated with the delivery location is available
locationRecId = this.tecDeliveryLocation();
if (locationRecId)
{
// Find a phone number associated with the postal delivery location
select firstonly TableId from locationChild
where locationChild.ParentLocation == locationRecId
join Location_Inv
where Location_Inv.RecId == locationChild.RecId
//&& locationChild.IsPostalAddress == NoYes::No
join Locator from logisticsElectronicAddress
where logisticsElectronicAddress.Location == locationChild.RecId
&& logisticsElectronicAddress.Type == LogisticsElectronicAddressMethodType::Email
&& logisticsElectronicAddress.Locator != '';
deliveryemail = logisticsElectronicAddress.Locator;
}
return deliveryemail;
}
EventHandler for Lookup
internal final class TECSalesTableForm_EventHandler
{
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[FormControlEventHandler(formControlStr(SalesTable, DeliveryContactname_Email), FormControlEventType::Lookup)]
public static void DeliveryContactname_Email_OnLookup(FormControl sender, FormControlEventArgs e)
{
Query lookupQuery;
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
LogisticsLocation Dlv_logisticsLocation;
LogisticsElectronicAddress Dlv_ElectronicAddress;
//SysReferenceTableLookup sysTableLookup;
// FormReferenceControl _formReferenceControl;
SysTableLookup sysTableLookup;
SalesTable salesTable = sender.formRun().dataSource(1).cursor();
// sysTableLookup = SysReferenceTableLookup::newParameters(tableNum(LogisticsElectronicAddress),sender , true);
sysTableLookup = SysTableLookup::newParameters(tableNum(LogisticsElectronicAddress),sender , true);
sysTableLookup.addLookupfield(fieldNum(LogisticsElectronicAddress, Locator));
sysTableLookup.addLookupfield(fieldNum(LogisticsElectronicAddress, Description));
select Dlv_logisticsLocation
where Dlv_logisticsLocation.ParentLocation == LogisticsPostalAddress::findRecId(salesTable.DeliveryPostalAddress).Location;
lookupQuery = new Query();
queryBuildDataSource = lookupQuery.addDataSource(tableNum(LogisticsElectronicAddress));
queryBuildRange = queryBuildDataSource.addRange(fieldNum(LogisticsElectronicAddress, Location));
queryBuildRange.value(strFmt("%1",Dlv_logisticsLocation.RecId));
queryBuildRange = queryBuildDataSource.addRange(fieldNum(LogisticsElectronicAddress, Type));
queryBuildRange.value(enum2str(LogisticsElectronicAddressMethodType::Email));
/////////////////////Start :Primary validation is removed on 14/07/2015 by BSIL RJ /////////
//queryBuildRange = queryBuildDataSource.addRange(fieldNum(LogisticsElectronicAddress, IsPrimary));
//queryBuildRange.value(enum2str(NoYes::Yes));
///////////////////END : 14/07/2015 //////////////////
sysTableLookup.parmQuery(lookupQuery);
/*Dlv_ElectronicAddress =*/ sysTableLookup.performFormLookup();
//return Dlv_ElectronicAddress;
}
}
Thankyou all.