Merging two queries ranges

HI Below sample code used to merge 2 queries ranges.

private void merge(Query _queryPRA, Query _this)
{
QueryBuildDataSource rpa, pfr;
int rpaRanges,i, rpaFilters;
QueryBuildRange range;
QueryFilter queryFilter;

//Fetch ranges from Query
rpaRanges =_queryPRA.dataSourceTable(tableNum(SalesTable)).rangeCount();
for (i=1 ; i<=rpaRanges; i++)
{
range = _queryPRA.dataSourceTable(tableNum(SalesTable)).range(i);

_this.dataSourceTable(tablenum(SalesTable)).addRange(_queryPRA.dataSourceTable(tableNum(SalesTable)).range(i).field()).value(queryValue(range.value()));
}

//fetch user filters from Dialog
rpaFilters = _queryPRA.queryFilterCount();

for (i=1 ; i<=rpaFilters; i++)
{
queryFilter = _queryPRA.queryFilter(i);

_this.dataSourceTable(tablenum(SalesTable)).addRange(fieldName2id(tableNum(SalesTable), _queryPRA.queryFilter(i).field())).value(queryValue(queryFilter.value()));
}
}

Advertisements

Report printing Extra page

Hi, If report printing extra page please check below logic.

Body Width <= Page Width – (Left Margin + Right Margin)

Horizontal usable area:

X = Page.Width – (Left Margin + Right Margin + Column Spacing)

Vertical usable area:

Y = Page.Height – (Top Margin + Bottom Margin + Header Height + Footer Height)

Any time objects on your report (including the Body itself) extend past the usable area either because they are defined like that or because they grow at runtime, the physical page renderers have no choice but to break onto a new page.

SQL in X++, range in where clause

Below case is when ‘AccessFeedsFilter’ has value it should fetch that reocrds only if its empty: it should fetch all

 

while select SKUNumber, ItemId, inventDimId,LifeCycleStatusFlag,ItemName, InboundDepth, InboundHeight, InboundWeight, InboundWidth,
OutboundDepth, OutboundHeight, OutboundWeight, OutboundWidth, ActualDepth, ActualHeight, ActualWeight, ActualWidth, RetailVariantId, Description, BasePrice
from productsAndVariants
where (productsAndVariants.LifeCycleStatusFlag == ogoParameters.AccessFeedsFilter && ogoParameters.AccessFeedsFilter != “”) || (ogoParameters.AccessFeedsFilter == “” && true)

Split text multiple lines in Email body

HI, Below smaple code used to show splited text in email body.

{

SysMailer mailer;
SysEmailParameters parameters;
InteropPermission permission = new InteropPermission(InteropKind::ComInterop);
OWIStoreTable OWIStoreTable;
Notes bodymsg, bodymsghtml;
ListIterator iterator;
List strlist=new List(Types::String);
;
permission.assert();
mailer = new SysMailer();
parameters = SysEmailParameters::find();

if (parameters.SMTPRelayServerName)
{
mailer.SMTPRelayServer(parameters.SMTPRelayServerName,
parameters.SMTPPortNumber,
parameters.SMTPUserName,
SysEmailParameters::password(),
parameters.NTLM);
}
else
{
mailer.SMTPRelayServer(parameters.SMTPServerIPAddress,
parameters.SMTPPortNumber,
parameters.SMTPUserName,
SysEmailParameters::password(),
parameters.NTLM);
}

mailer.fromAddress(‘test@AX.com’);
mailer.tos().appendAddress(‘AAA@gmail.com’);
mailer.subject(‘System Test’);

strlist =strSplit(‘AAA  BBB’,”\n”);

iterator = new ListIterator(strlist);

while(iterator.more())
{
bodymsg += strFmt(“%1<br>”,iterator.value());
iterator.next();
}

bodymsg = strReplace(bodymsg,’\n’,'<br>’);
bodymsg =bodymsg + “\n” + strFmt(“Last order %2 received for this webtore on: %1”, _lastSalesOrder.createdDateTime);

bodymsghtml= strFmtLB(bodymsg);

mailer.htmlBody(bodymsghtml);

mailer.sendMail();
}

Email sending using file template

HI, below sample code used to send email using Email tempalte formate in multiple lines and header formate.

static void sendMail(Email _defEmail, SysEmailId _emailTemplate, PurchTable PurchTable)
{
SysEmailParameters parameters = SysEmailParameters::find();
SMTPRelayServerName relayServer;
SMTPPortNumber portNumber;
SMTPUserName userName;
SMTPPassword password;
Str1260 subject;
Notes msgbody ;
InteropPermission interopPermission;
SysMailer mailer;
System.Exception e;

SysEmailTable table;
SysEmailMessageTable message;

str newMessageBody;

;

if(_defEmail)
{
if (parameters.SMTPRelayServerName)
relayServer = parameters.SMTPRelayServerName;
else
relayServer = parameters.SMTPServerIPAddress;

portNumber = parameters.SMTPPortNumber;
userName = parameters.SMTPUserName;
password = SysEmailParameters::password();

table = SysEmailTable::find(_emailTemplate);
message = SysEmailMessageTable::find(table.EmailId, table.DefaultLanguage);
if (message)
{
newMessageBody = VendorSendEmail::renderLetter(message,PurchTable);
}
subject = message.Subject;
msgbody = newMessageBody;

CodeAccessPermission::revertAssert();

try
{
interopPermission = new InteropPermission(InteropKind::ComInterop);
interopPermission.assert();
mailer = new SysMailer();
mailer.SMTPRelayServer(relayServer,portNumber,userName,password, parameters.NTLM);
mailer.fromAddress(SysUserInfo::find().Email);
mailer.tos().appendAddress(_defEmail);
mailer.subject(subject);
mailer.htmlBody(msgbody);
mailer.sendMail();
CodeAccessPermission::revertAssert();
info(“@CIT957”);
}
catch (Exception::CLRError)
{
e = ClrInterop::getLastException();

while (e)
{
info(e.get_Message());
e = e.get_InnerException();
}
CodeAccessPermission::revertAssert();
info (“error”);
}
}
else
error(“done”);

}

Reading text file data from folder

HI, Below sample code used to read multiple files

  1. Read data from file,Write to new file in different folder
  2. Delete files

Read and write file:

public void writeToHistoryFile(FilePath _fromFilePath)//Source filepath
{
#File
System.IO.StreamWriter streamWriterHistory;
Counter countFiles;
FileName fileNameHistory;
str inputLineHistory;
Set permissionSetHistory;
str directoryHistory, filePathHistory;
container fileListConHistory, record;
CommaTextIo commaTextIoHistory;

directoryHistory = _fromFilePath;
if(directoryHistory == “”)
{
return;
}
fileListConHistory = this.findMatchingFiles(directoryHistory);
//permissionSetHistory.add(new InteropPermission(InteropKind::ClrInterop));
for (countFiles=1; countFiles <= conlen(fileListConHistory); countFiles++)
{
ttsBegin;
inputLineHistory = “”;
fileNameHistory = “Newfolderpath”;

fileNameHistory += “\\newfilename”+”_”+Winapi::createGUID()+”_”;
fileNameHistory += date2Str(today(), 213, 2, DateSeparator::None, 2, DateSeparator::None, 4);
fileNameHistory +=” “;
fileNameHistory += time2str(timeNow(),TimeSeparator::Dot, TimeFormat::AMPM);
fileNameHistory += “.txt”;
streamWriterHistory= new System.IO.StreamWriter(fileNameHistory,
false,
System.Text.Encoding::GetEncoding(28591));

permissionSetHistory = new Set(Types::Class);

permissionSetHistory.add(new InteropPermission(InteropKind::ClrInterop));
filePathHistory = conPeek(fileListConHistory,countFiles);

permissionSetHistory.add(new FileIOPermission(filePathHistory, ‘r’));
permissionSetHistory.add(new FileIOPermission(filePathHistory, ‘rw’));
CodeAccessPermission::assertMultiple(permissionSetHistory);

commaTextIoHistory = new CommaTextIo(filePathHistory,#io_read);
if (! commaTextIoHistory || commaTextIoHistory.status() != IO_Status::Ok)
{
throw error(“@SYS19358”);
}
while (commaTextIoHistory.status() == IO_Status::Ok)
{
record = commaTextIoHistory.read();

if(!record)
{
CodeAccessPermission::revertAssert();
break;
}

//record = conIns(record, conLen(record) +1);
if(!inputLineHistory)
inputLineHistory = con2Str(record);
else
inputLineHistory = “\n” + con2Str(record);

streamWriterHistory.WriteLine(inputLineHistory,true);
}
CodeAccessPermission::revertAssert();

// }
streamWriterHistory.Close();
commaTextIoHistory.finalize();
ttsCommit;
}
}

Delete file:

static boolean importFromWorkstation(FilePath _deleteFile = “”)
{
//MPSWorkstation _tWorkstation
int iNumberOfFiles;
FileName sFileName,fileNamePerm, inFile;
InteropPermission interopPerm;
Set permissionSet, permSetFiles;
System.Array files;
int i, j;
container fList;
#File
;

permissionSet = new Set(Types::Class);
permissionSet.add(new InterOpPermission(InteropKind::ClrInterop));

CodeAccessPermission::assertMultiple(permissionSet);

files = System.IO.Directory::GetFiles(_deleteFile);
for( i=0; i<ClrInterop::getAnyTypeForObject(files.get_Length()); i++ )
{
fList = conins(fList, conlen(fList)+1, ClrInterop::getAnyTypeForObject(files.GetValue(i)));
}

for(j=1;j<=conlen(fList); j++)

{
sFileName = conpeek(fList, j);
inFile = sFileName;
ttsbegin;

System.IO.File::Delete(inFile);

ttscommit;
}
CodeAccessPermission::revertAssert();

return true;
}

getting standard Shipping and Tax for SO

HI, Below sample code used to get shipping charges for sales order.

static real shippingCharges(SalesId _salesId)
{
QueryRun queryRun;
OSSDeliveryChargeTable deliveryChargeTable, table;
DlvMode mode;
SalesTable _salesTable = SalesTable::find(_salesId);
real shipping;
;

queryRun = new QueryRun(OSSDlvMode::query(_salesTable.CustAccount, _salesTable, _salesTable.DlvMode,
OCSCatalogueTable::find(OCSBrandTable::find(_salesTable.OSSBrandId).CatalogueId, false).ShippingChargegroupId));

while(queryRun.next())
{
deliveryChargeTable = queryRun.get(tablenum(OSSDeliveryChargeTable));
table = deliveryChargeTable;
if(deliveryChargeTable)
{
_salesTable.ossCreateMarkupTransFromChargeRecord(true, deliveryChargeTable, deliveryChargeTable.DlvModeId);
}
}
shipping = MarkupTrans::ossCalculateDeliveryCharges(_salesTable);

return shipping;
}

Getting tax(multiple ways):

displayFields = SalesTotals::displayFieldsServer(SalesTable::find(oldSalesId), SalesUpdate::All, ‘USD’);

tax = conPeek(displayFields, 16);
ossOrderValue.Tax = Tax;
if(!ossOrderValue.Tax)
ossOrderValue.Tax = SalesTable::find(oldSalesId).ossTaxCalc();
if(!ossOrderValue.Tax)
{
while select salesLineTax
where salesLineTax.SalesId == oldSalesId
{
tax += Tax::calcTaxAmount(salesLineTax.TaxGroup, salesLineTax.TaxItemGroup, Systemdateget(), salesLineTax.CurrencyCode,
salesLineTax.LineAmount + ossOrderValue.ShippingCharges, TaxModuleType::Sales);
}

ossOrderValue.Tax = tax;
}