We all come across the requirements where the contact information for the customer is entered in a wrongly manner or there's whole set of records where the information provided is completely garbage.
For me it was Email and Mobile.
So we extracted data and narrowed it down to list of customers with garbage values.
For this I have prepared one csv file mainly consisting four columns.
1) Account
2) Garbage info Email/Mobile
3) Identifier Email/Mobile
4) Add for modifying existing number.
Below is the code to call the same from RunnableClass
{
/// <summary>
/// Runs the class with the specified arguments.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
#define.LocationRoleName('Collection')
AsciiStreamIo file;
Array fileLines;
FileUploadTemporaryStorageResult fileUpload;
str custid;
CustTable custTable;
LogisticsElectronicAddress electronicAddress;
DirPartyTable dirPartyTable;
DirPartyLocation partyLocation;
LogisticsElectronicAddressLocator cleanupdata;
Name identifier, editnumber;
fileUpload = File::GetFileFromUser() as FileUploadTemporaryStorageResult;
if(fileUpload != null)
{
file = AsciiStreamIo::constructForRead(fileUpload.openResult());
if (file)
{
if (file.status())
{
throw error("@SYS52680");
}
file.inFieldDelimiter(',');
file.inRecordDelimiter('\r\n');
}
container record;
while (!file.status())
{
record = file.read();
if (conLen(record))
{
custid = strFmt("%1",conPeek(record,1));
cleanupdata = strFmt("%1",conPeek(record,2));
identifier = strFmt("%1",conPeek(record,3));
editnumber = strFmt("%1",conPeek(record,4));
ttsbegin;
if(identifier == 'Email')
{
select forupdate electronicAddress
join partyLocation where partyLocation.LOCATION == electronicAddress.LOCATION
join CustTable where CustTable.PARTY == partyLocation.PARTY
&& CustTable.AccountNum == custid
&& electronicAddress.Locator == cleanupdata
&& electronicAddress.Type == LogisticsElectronicAddressMethodType::Email;
if(electronicAddress.RecId != 0)
{
electronicAddress.delete();
}
}
if(identifier == 'Mobile')
{
select forupdate electronicAddress
join partyLocation where partyLocation.LOCATION == electronicAddress.LOCATION
join CustTable where CustTable.PARTY == partyLocation.PARTY
&& CustTable.AccountNum == custid
&& electronicAddress.Locator == cleanupdata
&& electronicAddress.Type == LogisticsElectronicAddressMethodType::Phone;
if(electronicAddress.RecId == 0)
{
select forupdate electronicAddress
join partyLocation where partyLocation.LOCATION == electronicAddress.LOCATION
join CustTable where CustTable.PARTY == partyLocation.PARTY
&& CustTable.AccountNum == custid
&& (electronicAddress.Locator == strFmt("0%1",cleanupdata) || electronicAddress.Locator == strFmt("00%1",cleanupdata))
&& electronicAddress.Type == LogisticsElectronicAddressMethodType::Phone;
}
if(electronicAddress.RecId != 0)
{
if (editnumber == "Add +" || editnumber == "Add +971")
{
electronicAddress.Locator = (editnumber=="Add +" ? strFmt("+%1",cleanupdata) : strFmt("+971%1",cleanupdata) );
electronicAddress.update();
}
else
{
electronicAddress.delete();
}
}
}
ttscommit;
}
}
info("done");
}
}
}
Comments
Post a Comment