add LedgerTrans.DocumentNum field to BankAccountStatment report - axapta

I want to add LedgerTrans.DocumentNum field to BankAccountStatment report
BankAccountStatment report has a datasource "BankAccountTable"
How can I perfrom this?
Note: LedgerTrans.DocumentNum can be reached through BankAccoutTrans.AccountId = BankAccountTable.AccountId then LedgerTrans.voucher = BankAccountTrans.Voucher

You can try declaring LedgerTrans ledgerTrans; in classDeclaration and adding following code in the report's fetch method before calling element.send(bankAccountTrans):
select firstonly ledgerTrans
where ledgerTrans.TransDate == bankAccountTrans.TransDate
&& ledgerTrans.Voucher == bankAccountTrans.Voucher
&& ledgerTrans.DocumentNum != "";
After that you'd only need to add a new display field in the ReportDesign\AutoDesignSpecs\Body:_2 section with the following code:
//BP Deviation Documented
display DocumentNum documentNum()
{
return ledgerTrans.DocumentNum;
}
I didn't try it but it should work. As an alternative you can declare ledgerTrans in the fetch method, add element.send(ledgerTrans) after selecting ledgerTrans, and add a standard String field in the section mentioned above, Table=LedgerTrans, DataField=DocumentNum. Then no display method is needed.
P.S. I assumed you're using AX 2009 but for other versions of AX the logic remains the same.

This is simple:
display DocumentNum documentNum()
{
return (select firstonly DocumentNum from ledgerTrans
where ledgerTrans.TransDate == bankAccountTrans.TransDate
&& ledgerTrans.Voucher == bankAccountTrans.Voucher
&& ledgerTrans.DocumentNum != "").DocumentNum;
}
Drag the method to the desired print location.

Related

Set default data in field x++ PurchCreateOrder

I want to set a default value based on curUserid() in PurchCreateOrder. How can I put data in my field on form extension ?
Is there any better option of doing this ? Fields are bound to datasource and I have different fields with differentdatasources.
My code is giving me abnormal termination error with nullreferences. XPPCompiler
[ExtensionOf(tableStr(PurchTable))]
final class PurchCreateOrderGetDefAdress_Extension
{
void initvalue(PurchaseType _purchaseType)
{
next initvalue(_purchaseType);
PurchTable purchtable;
LogisticsPostalAddress logpostadress;
UserInfoSz usrsz;
str user = curUserId();
select firstonly logpostadress where logpostadress.city == 'lub';
// select firstonly InventSiteId, InventLocationId from purchtable join usrsz where purchtable.InventSiteId == usrsz.InventSiteId && usrsz.IsDefault == true;
select firstonly InventSiteId from usrsz where usrsz.UserId == user && usrsz.IsDefault == true;
purchtable.initValue();
purchtable.deliveryname = 'asasasasas' ;//logpostadress.Address;
purchtable.inventsiteid = usrsz.InventSiteId;
purchtable.inventlocationid = usrsz.InventSiteId;
info(strFmt("%1, %2, %3", logpostadress.Address, usrsz.InventSiteId));
}
}
The error is straight forward.
Error The augmented class 'PurchTable' provides a method by this name, but this method cannot be used as a chain of command method since the parameter profile does not match the original method.
Take a look at the highlighted parameter profile and compare to yours.
Edit: Take a look at these links for more info on Chain of Command (CoC):
https://learn.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/extensibility/method-wrapping-coc
https://channel9.msdn.com/Blogs/mfp/X-Chain-Of-Command (This video is excellent)

While select with if statement syntax - what is the purpose of the if statement?

I have come across a strange syntax that I have never seen in x++ before, but it compiles and works (as far as I can tell). I was curious if anybody has seen or used this before and could explain: what is the purpose of the if statement within the context of a while select?
InventBatch inventBatch;
InventTrans inventTrans;
InventTransOrigin inventTransOrigin;
InventDim inventDim;
ttsBegin;
while select Qty, DatePhysical from inventTrans
where inventTrans.StatusReceipt == StatusReceipt::Arrived
join inventTransOrigin
where inventTransOrigin.RecId == inventTrans.InventTransOrigin
&& inventTransOrigin.InventTransId == "SomeIdFromSomewhere"
join inventDim
where inventDim.inventDimId == inventTrans.inventDimId
&& inventDim.inventBatchId
if (inventTrans)
{
inventBatch = InventBatch::find(inventDim.inventBatchId, inventTrans.ItemId, true);
inventBatch.Field1 = inventTrans.Qty;
inventBatch.Field2 = inventTrans.DatePhysical;
inventBatch.update();
}
ttsCommit;
When you do a while select, generally you put {} to wrap your code, but you can also do the same thing as if statements, if you omit the {} and the immediately proceeding line gets executed for each loop.
if (true)
info("Hello World");
if (true)
{
info("Hello World");
}
while select SalesTable
info(SalesTable.SalesId);
while select SalesTable
{
info(SalesTable.SalesId);
}
Regarding the code you have typed above, it's idiotic. In AX, in older versions of the code if (common) would often only evaluate common.RecId != 0, but in later ones, I believe it will evaluate true if the buffer is returned with some data. In a while select however, it will always return true as the select is only returning records when it's true.
You could/should just delete literally only the if (inventTrans) line and leave the brackets and it will be readable/normal code.

How to get total number of rows in a drupal view alter hook?

I've to avoid duplicate search result in a view, so what I am trying to alter the view using pre render hook. and removing the duplicates it's working fine but the problem is in the count of result. it shows the count from the query executed and this include the duplicated item too. also, I enabled the pagination with limit of 5 in a page. then the count seems to be strange it's taking the count of the elements showing in each page
function search_helper_views_pre_render(\Drupal\views\ViewExecutable $view) {
if ($view->id() == "all_news" || $view->id() == "all_publications" || $view->id() == "all_events" || $view->id() == "global_search") {
$unique_nids = $d_nids = $new_results = array();
// Loop through results and filter out duplicate results.
foreach($view->result as $key => $result) {
if(!in_array($result->nid, $unique_nids)) {
$unique_nids[] = $result->nid;
}
else {
unset($view->result[$key]);
}
}
$view->total_rows = count($view->result);
//$view->pager->total_items = count($view->result);
$view->pager->updatePageInfo();
}
}
the expected output of the $view->total_rows must be the total count of result instead of count of elements shown in the page.
You totaly done it in wrong way. as you see ( and it's clear from its name ), it's hook__views_pre_render it runs before the rendering. So its really hard to manipulate the views results and counter, pagination there.
As I see in your query you just remove duplicate Nids , so you can easily do it by Distinct drupal views feature.
Under Advanced, query settings, click on settings.
You will get this popup, now checkmark Distinct
Could do
$difference = count($view->result) - count($new_result);
$view->total_rows = $view->total_rows - $difference;
BTW Distinct setting doesn't always work, see https://www.drupal.org/project/drupal/issues/2993688

D365 New Button creates price line with empty line

After adding logic about creating price for object in grid it's always created "one line more" which is empty.
So, if there is need to be created two lines, it will be created 3 lines and that one addition will be empty.
Is there something what I missing in code?
[Control("CommandButton")]
class AreaActionPaneNew
{
void clicked()
{
PMCParameters contractParameters = PMCParameters::find();
PMETmpRentalObjectArea groupedAreaList; // Group by area_type and cost_type
PMERentalObjectPrice priceList;
date workingDate = currWorkingDate.dateValue();
;
super();
// Get grouped area values. Values are summed up by area_type and ancost_type
groupedAreaList = PMERentalObjectAreaCl::getRentalAreaPrCostType(pmeRentalobject.RentalObjectId, userSetting.validFrom(), userSetting.validTo() , workingDate);
ttsbegin;
while select groupedAreaList
{
select forupdate firstonly priceList
where priceList.RentalObjectId == pmeRentalObject.RentalObjectId &&
priceList.RentalCostType == groupedAreaList.RentalCostTypeId &&
priceList.AreaType == groupedAreaList.Areatype && priceList.ValidFrom == pmeRentalObject.ValidFrom;
if (!priceList)
priceList.initValue();
priceList.RentalObjectId = pmeRentalObject.RentalObjectId;
priceList.RentalCostType = groupedAreaList.RentalCostTypeId;
priceList.ValidFrom = pmeRentalobject.ValidFrom;
priceList.AreaType = groupedAreaList.Areatype;
priceList.Amount = groupedAreaList.Price;
priceList.Area = groupedAreaList.AreaValue;
priceList.Quantity = groupedAreaList.RentalQty;
if (!priceList)
priceList.Period = contractParameters.ReportPeriod;
if (priceList)
priceList.update();
else
priceList.insert();
}
ttscommit;
pmeRentalObjectPrice_ds.research();
}
}
The code looks like it only updates/inserts without creating a blank line.
From your attribute, you are using a Command Button (see here), which may have an associated command, such as New, which effectively pushes Ctrl+N, and would explain why you have a blank line.
The simplest way to check is just create a regular Button and override the clicked method, then copy/paste your code and push both buttons and see if they have different behavior.
Check the Command property on the button and see if there's something there. Try commenting out the super(); call.
You should perhaps consider just a Button or a Menu Item Button with an associated object.

Is there a way to improve this dynamics ax update job

I'm working on an AX 2009 installation. The job is to update the WMSOrderTrans table. Here is what I have got so far:
WMSOrderTrans wmsOrderTrans;
;
while select wmsOrderTrans
{
if (wmsOrderTrans.BBBpackingSlipExists())
{
ttsBegin;
wmsOrderTrans.selectForUpdate(true);
wmsOrderTrans.BBBPackingSlipExists = NoYes::Yes;
wmsOrderTrans.doUpdate();
ttsCommit;
}
}
The job takes about an hour to finish on the test system. This makes me worry about the performance on the production system.
At the moment the code has been written like this to have minimal locking issues (selectForUpdate is done for each row if it should be updated and is then immediatly committed). The reason is, that users will be working on the system, when the job is running.
My question is, if there is a reasonable way to implement this job in a way with less transaction overhead.
while select forUpdate ...
... does not seem to be an option, because it would lock the table until the job is finished.
Any input is appreciated.
This is the code for the BBBPackingSlipExists method:
display boolean BBBpackingSlipExists()
{
InventDim inventDimCur;
InventDim inventDimPackSlip;
InventTrans inventTransPackSlip;
;
select firstonly RecId from inventTransPackSlip
where inventTransPackSlip.InventTransId == this.inventTransId
&& (inventTransPackSlip.StatusIssue == StatusIssue::Deducted
|| inventTransPackSlip.StatusIssue == StatusIssue::Sold)
&& !inventTransPackSlip.PackingSlipReturned
exists join inventDimCur
where inventDimCur.inventDimId == this.inventDimId
exists join inventDimPackSlip
where inventDimPackSlip.inventDimId == inventTransPackSlip.inventDimId
&& inventDimCur.inventSerialId == inventDimPackSlip.inventSerialId
;
if (inventTransPackSlip.RecId != 0 && this.isReserved)
{
return true;
}
return false;
}
This looks like a prime candidate to convert to set based logic, I'd go for something like this. Please note that the job isn't tested at all since I don't have a 2009 environment handy (this doesn't even compile on 2012) so if you need to change the code feel free to edit it into my answer.
Note that the isreserved check is built into the query as well as the exists joins from the packingslipexists method
static void Job250(Args _args)
{
WMSOrderTrans wmsOrderTrans;
InventDim inventDimCur;
InventDim inventDimPackSlip;
InventTrans inventTransPackSlip;
;
wmsOrderTrans.skipDatabaseLog(true);
wmsOrderTrans.skipDataMethods(true);
wmsOrderTrans.skipEvents(true);
update_recordset wmsOrderTrans setting BBBPackingSlipExists = NoYes::Yes
where wmsOrderTrans.isReserved
exists join inventTransPackSlip
where inventTransPackSlip.InventTransId == wmsOrderTrans.inventTransId
&& (inventTransPackSlip.StatusIssue == StatusIssue::Deducted
|| inventTransPackSlip.StatusIssue == StatusIssue::Sold)
&& !inventTransPackSlip.PackingSlipReturned
exists join inventDimCur
where inventDimCur.inventDimId == wmsOrderTrans.inventDimId
exists join inventDimPackSlip
where inventDimPackSlip.inventDimId == inventTransPackSlip.inventDimId
&& inventDimCur.inventSerialId == inventDimPackSlip.inventSerialId;
}
See the documentation on update_recordset and why the skip* methods might be necessary

Resources