Export:
[ExtensionOf(classStr(PcModelVisitorExport))]
final class PCModelVisitorExport_Extension
{
public void visitStart(Common _record)
{
next visitStart(_record);
if (_record is EcoResAttribute)
{
if ( this.writeComponent() )
{
EcoResAttribute ecoResAttribute = _record;
this.writeFieldValueInt(ecoResAttribute, fieldId2name(ecoResAttribute.TableId, fieldNum(EcoResAttribute, NoPrint)), ecoResAttribute.NoPrint);
}
}
if (_record is PCPriceExpressionValue)
{
PCPriceExpressionValue priceExpressionValue = _record;
this.writeFieldValue(priceExpressionValue, fieldId2name(priceExpressionValue.TableId, fieldNum(PCPriceExpressionValue, SalesOptionId)), priceExpressionValue.SalesOptionId);
}
if (_record is PCPriceExpressionRule)
{
PCPriceExpressionRule priceExpressionRule = _record;
this.writeFieldValue(priceExpressionRule, fieldId2name(priceExpressionRule.TableId, fieldNum(PCPriceExpressionRule, SalesOptionId)), priceExpressionRule.SalesOptionId);
}
}
}
Import:
[ExtensionOf(classStr(PCImportComponentAttributeHandler))]
final class PCImportComponentAttributeHandler_Extension
{
protected void importData()
{
#define.NoPrint('NoPrint')
next importData();
ttsbegin;
attribute.Selectforupdate(true);
attribute.NoPrint = this.getIntFieldByName(#NoPrint);
attribute.update();
ttscommit;
}
}
[ExtensionOf(classStr(PCImportPriceExpressionRuleHandler))]
final class PCImportPriceExpressionRuleHandler_Extension
{
protected void importData()
{
#define.SalesOptionId('SalesOptionId')
next importData();
ttsbegin;
expressionRule.Selectforupdate(true);
expressionRule.SalesOptionId = this.getFieldByName(#SalesOptionId);
expressionRule.update();
ttscommit;
}
}
Wednesday, October 24, 2018
Time and attendance-Clock-in/out(punch clock) to filter the Indirect Activities based on the Resource group attached.
[ExtensionOf(formStr(JmgRegistration))]
final class JmgRegistration_Extension
{
public QueryBuildDataSource qbdsJmgIpcActivityIndirectactivity;
public container containerActivityId, conResourceGroup;
public void showIPC()
{
WrkCtrTable selectedWrkCtrTable;
WrkCtrResourceGroup wrkCtrResourceGroup;
next showIPC();
containerActivityId = conNull();
conResourceGroup = conNull();
//Filter the data based on the resource group
if (curWrkCtrId)
{
conResourceGroup += curWrkCtrId;
selectedWrkCtrTable = WrkCtrTable::find(curWrkCtrId);
//Checking for only resource groups but not resources in the WrkCtrTable.
if (selectedWrkCtrTable.IsIndividualResource == NoYes::No)
{
this.JmgIpcActivityIndirectactivityRange();
}
}
//Filter the data based on the production unit with no resource group
if(curProdUnitId && !curWrkCtrId)
{
//Fetching the list of resource group that are attached to a production unit.
while select wrkCtrId from wrkCtrResourceGroup
where wrkCtrResourceGroup.ProdUnitId == curProdUnitId
{
conResourceGroup += wrkCtrResourceGroup.WrkCtrId;
}
this.JmgIpcActivityIndirectactivityRange();
}
jmgJobTable_DS.executeQuery();
}
//Filter the form datasource JmgJobTable_ds based on the activityID list.
public void JmgIpcActivityIndirectactivityRange()
{
Query queryJmgIpResourceGroup, queryJmgIpActivity;
QueryBuildDataSource qbdsJmgIpResourceGroup, qbdsJmgIpActivity;
QueryBuildRange qbrJmgIpResourceGroup, qbrJmgIpActivity;
QueryRun qrJmgIpResourceGroup, qrJmgIpActivity;
WrkCtrResourceGroup wrkCtrResourceGroup;
JmgIpcActivity jmgIpActivity;
JmgIpActivityResourceGroup jmgIpResourceGroup;
//Query to fetch the list of activityID's with the resource groups attached.
queryJmgIpResourceGroup = new Query();
qbdsJmgIpResourceGroup = queryJmgIpResourceGroup.addDataSource(tableNum(JmgIpActivityResourceGroup));
qbdsJmgIpResourceGroup.addGroupByField(fieldNum(JmgIpActivityResourceGroup, Activity));
qbdsJmgIpResourceGroup.addGroupByField(fieldNum(JmgIpActivityResourceGroup, WrkCtrId));
qbrJmgIpResourceGroup = qbdsJmgIpResourceGroup.addRang e(fieldNum(JmgIpActivityResourceGroup, WrkCtrId));
qbrJmgIpResourceGroup.value(con2Str(conResourceGroup));
qbdsJmgIpActivity = qbdsJmgIpResourceGroup.addDataSource(tableNum(JmgIpcActivity));
qbdsJmgIpActivity.joinMode(JoinMode::ExistsJoin);
qbdsJmgIpActivity.addLink(fieldNum(JmgIpActivityResourceGroup, Activity),fieldNum(JmgIpcActivity, Activity));
qrJmgIpResourceGroup = new QueryRun(queryJmgIpResourceGroup);
while (qrJmgIpResourceGroup.next())
{
jmgIpResourceGroup = qrJmgIpResourceGroup.get(tableNum(JmgIpActivityResourceGroup));
containerActivityId += jmgIpResourceGroup.Activity;
}
//Query to fetch the list of activityID's without the resource group
queryJmgIpActivity = new Query();
qbdsJmgIpActivity = queryJmgIpActivity.addDataSource(tableNum(JmgIpcActivity));
qbdsJmgIpResourceGroup = qbdsJmgIpActivity.addDataSource(tableNum(JmgIpActivityResourceGroup));
qbdsJmgIpResourceGroup.joinMode(JoinMode::NoExistsJoin);
qbdsJmgIpResourceGroup.addLink(fieldNum(JmgIpcActivity, Activity),fieldNum(JmgIpActivityResourceGroup, Activity));
qrJmgIpActivity = new QueryRun(queryJmgIpActivity);
while (qrJmgIpActivity.next())
{
jmgIpActivity = qrJmgIpActivity.get(tableNum(JmgIpcActivity));
containerActivityId += jmgIpActivity.Activity;
}
//Final query to filter the data in the JmgJobTable_ds based on the activityID list.
qbdsJmgIpcActivityIndirectactivity = qbdsJmgJobTable.addDataSource(tableNum(JmgIpcActivity));
qbdsJmgIpcActivityIndirectactivity.joinMode(JoinMode::ExistsJoin);
qbdsJmgIpcActivityIndirectactivity.addLink(fieldNum(JmgJobTable, JobId),fieldNum(JmgIpcActivity, JobId));
qbdsJmgIpcActivityIndirectactivity.addRange(fieldNum(JmgIpcActivity, Activity)).value(con2Str(containerActivityId));
}
public void removeJmgIpcActivityIndirectactivityRange()
{
if (qbdsJmgIpcActivityIndirectactivity)
{
qbdsJmgIpcActivityIndirectactivity.enabled(false);
}
}
}
// To remove the newly build query when standard query being executed and thus making the datasource to work based on the standard behaviour.
class JmgRegistrationsEventHandlers
{
[PreHandlerFor(formStr(JmgRegistration), formMethodStr(JmgRegistration, showProductionJobs))]
public static void JmgRegistration_Pre_showProductionJobs(XppPrePostArgs args)
{
FormRun jmgRegistration = args.getThis();
jmgRegistration.removeJmgIpcActivityIndirectactivityRange();
}
[PreHandlerFor(formStr(JmgRegistration), formMethodStr(JmgRegistration, showProject))]
public static void JmgRegistration_Pre_showProject(XppPrePostArgs args)
{
FormRun jmgRegistration = args.getThis();
jmgRegistration.removeJmgIpcActivityIndirectactivityRange();
}
[PreHandlerFor(formStr(JmgRegistration), formMethodStr(JmgRegistration, showIPC))]
public static void JmgRegistration_Pre_showIPC(XppPrePostArgs args)
{
FormRun jmgRegistration = args.getThis();
jmgRegistration.removeJmgIpcActivityIndirectactivityRange();
}
}
final class JmgRegistration_Extension
{
public QueryBuildDataSource qbdsJmgIpcActivityIndirectactivity;
public container containerActivityId, conResourceGroup;
public void showIPC()
{
WrkCtrTable selectedWrkCtrTable;
WrkCtrResourceGroup wrkCtrResourceGroup;
next showIPC();
containerActivityId = conNull();
conResourceGroup = conNull();
//Filter the data based on the resource group
if (curWrkCtrId)
{
conResourceGroup += curWrkCtrId;
selectedWrkCtrTable = WrkCtrTable::find(curWrkCtrId);
//Checking for only resource groups but not resources in the WrkCtrTable.
if (selectedWrkCtrTable.IsIndividualResource == NoYes::No)
{
this.JmgIpcActivityIndirectactivityRange();
}
}
//Filter the data based on the production unit with no resource group
if(curProdUnitId && !curWrkCtrId)
{
//Fetching the list of resource group that are attached to a production unit.
while select wrkCtrId from wrkCtrResourceGroup
where wrkCtrResourceGroup.ProdUnitId == curProdUnitId
{
conResourceGroup += wrkCtrResourceGroup.WrkCtrId;
}
this.JmgIpcActivityIndirectactivityRange();
}
jmgJobTable_DS.executeQuery();
}
//Filter the form datasource JmgJobTable_ds based on the activityID list.
public void JmgIpcActivityIndirectactivityRange()
{
Query queryJmgIpResourceGroup, queryJmgIpActivity;
QueryBuildDataSource qbdsJmgIpResourceGroup, qbdsJmgIpActivity;
QueryBuildRange qbrJmgIpResourceGroup, qbrJmgIpActivity;
QueryRun qrJmgIpResourceGroup, qrJmgIpActivity;
WrkCtrResourceGroup wrkCtrResourceGroup;
JmgIpcActivity jmgIpActivity;
JmgIpActivityResourceGroup jmgIpResourceGroup;
//Query to fetch the list of activityID's with the resource groups attached.
queryJmgIpResourceGroup = new Query();
qbdsJmgIpResourceGroup = queryJmgIpResourceGroup.addDataSource(tableNum(JmgIpActivityResourceGroup));
qbdsJmgIpResourceGroup.addGroupByField(fieldNum(JmgIpActivityResourceGroup, Activity));
qbdsJmgIpResourceGroup.addGroupByField(fieldNum(JmgIpActivityResourceGroup, WrkCtrId));
qbrJmgIpResourceGroup = qbdsJmgIpResourceGroup.addRang e(fieldNum(JmgIpActivityResourceGroup, WrkCtrId));
qbrJmgIpResourceGroup.value(con2Str(conResourceGroup));
qbdsJmgIpActivity = qbdsJmgIpResourceGroup.addDataSource(tableNum(JmgIpcActivity));
qbdsJmgIpActivity.joinMode(JoinMode::ExistsJoin);
qbdsJmgIpActivity.addLink(fieldNum(JmgIpActivityResourceGroup, Activity),fieldNum(JmgIpcActivity, Activity));
qrJmgIpResourceGroup = new QueryRun(queryJmgIpResourceGroup);
while (qrJmgIpResourceGroup.next())
{
jmgIpResourceGroup = qrJmgIpResourceGroup.get(tableNum(JmgIpActivityResourceGroup));
containerActivityId += jmgIpResourceGroup.Activity;
}
//Query to fetch the list of activityID's without the resource group
queryJmgIpActivity = new Query();
qbdsJmgIpActivity = queryJmgIpActivity.addDataSource(tableNum(JmgIpcActivity));
qbdsJmgIpResourceGroup = qbdsJmgIpActivity.addDataSource(tableNum(JmgIpActivityResourceGroup));
qbdsJmgIpResourceGroup.joinMode(JoinMode::NoExistsJoin);
qbdsJmgIpResourceGroup.addLink(fieldNum(JmgIpcActivity, Activity),fieldNum(JmgIpActivityResourceGroup, Activity));
qrJmgIpActivity = new QueryRun(queryJmgIpActivity);
while (qrJmgIpActivity.next())
{
jmgIpActivity = qrJmgIpActivity.get(tableNum(JmgIpcActivity));
containerActivityId += jmgIpActivity.Activity;
}
//Final query to filter the data in the JmgJobTable_ds based on the activityID list.
qbdsJmgIpcActivityIndirectactivity = qbdsJmgJobTable.addDataSource(tableNum(JmgIpcActivity));
qbdsJmgIpcActivityIndirectactivity.joinMode(JoinMode::ExistsJoin);
qbdsJmgIpcActivityIndirectactivity.addLink(fieldNum(JmgJobTable, JobId),fieldNum(JmgIpcActivity, JobId));
qbdsJmgIpcActivityIndirectactivity.addRange(fieldNum(JmgIpcActivity, Activity)).value(con2Str(containerActivityId));
}
public void removeJmgIpcActivityIndirectactivityRange()
{
if (qbdsJmgIpcActivityIndirectactivity)
{
qbdsJmgIpcActivityIndirectactivity.enabled(false);
}
}
}
// To remove the newly build query when standard query being executed and thus making the datasource to work based on the standard behaviour.
class JmgRegistrationsEventHandlers
{
[PreHandlerFor(formStr(JmgRegistration), formMethodStr(JmgRegistration, showProductionJobs))]
public static void JmgRegistration_Pre_showProductionJobs(XppPrePostArgs args)
{
FormRun jmgRegistration = args.getThis();
jmgRegistration.removeJmgIpcActivityIndirectactivityRange();
}
[PreHandlerFor(formStr(JmgRegistration), formMethodStr(JmgRegistration, showProject))]
public static void JmgRegistration_Pre_showProject(XppPrePostArgs args)
{
FormRun jmgRegistration = args.getThis();
jmgRegistration.removeJmgIpcActivityIndirectactivityRange();
}
[PreHandlerFor(formStr(JmgRegistration), formMethodStr(JmgRegistration, showIPC))]
public static void JmgRegistration_Pre_showIPC(XppPrePostArgs args)
{
FormRun jmgRegistration = args.getThis();
jmgRegistration.removeJmgIpcActivityIndirectactivityRange();
}
}
Wednesday, June 27, 2018
What is the "Quantity Adjustment" Button in Inventory management In D365/Axapta.
It is very important to know the Quantity Adjustment through Inventory Management-Onhand Form.
It appears to create a single transaction with no Journal ID.
1. What is the purpose of this form?
Using this form for adjusting inventory quantity is basically identical to posting an counting journal for a specific item.
2. Can we add logging to it? what journal is used?
You can identify the transaction through the item transaction form but cannot open the counting journal as an ordinary user from the AX client.
3. What will be impact on costing if we adjust quantity using this form?
The impact on your costing will be that the inventory value is reduced or increased based on the number of items you specified to be on stock.
The technical information such as the trace log and classes related to this posting below:
\Data Dictionary\Tables\InventSite\Methods\changeDimension 29
\Classes\InventMov_Vir_Counting\defaultDimension 3
\Classes\InventUpdate\initInventTransPosting 8
\Classes\InventUpdate\updateInventTransPosting 5
\Classes\InventUpd_Physical\updateInventTransPosting 18
\Classes\InventUpd_Physical\updateNow 69
\Classes\InventUpd_Financial\updateNow 49
\Classes\WMSOnlineCountingServer\handleLine 73
\Classes\WMSOnlineCountingServer\run 19
\Classes\WMSOnlineCountingServer\validateRun 3
\Classes\WMSOnlineCounting\validateRun 3
\Forms\WMSOnlineCounting\Methods\canClose 9
\Classes\FormRun\closeOk
After updating the quantity and clicking OK button the above trace log is generated.
It will update the quantity and financial dimension will update if settings exist on item or site. But, no journal number exist in counting journal.
It appears to create a single transaction with no Journal ID.
1. What is the purpose of this form?
Using this form for adjusting inventory quantity is basically identical to posting an counting journal for a specific item.
2. Can we add logging to it? what journal is used?
You can identify the transaction through the item transaction form but cannot open the counting journal as an ordinary user from the AX client.
3. What will be impact on costing if we adjust quantity using this form?
The impact on your costing will be that the inventory value is reduced or increased based on the number of items you specified to be on stock.
The technical information such as the trace log and classes related to this posting below:
\Data Dictionary\Tables\InventSite\Methods\changeDimension 29
\Classes\InventMov_Vir_Counting\defaultDimension 3
\Classes\InventUpdate\initInventTransPosting 8
\Classes\InventUpdate\updateInventTransPosting 5
\Classes\InventUpd_Physical\updateInventTransPosting 18
\Classes\InventUpd_Physical\updateNow 69
\Classes\InventUpd_Financial\updateNow 49
\Classes\WMSOnlineCountingServer\handleLine 73
\Classes\WMSOnlineCountingServer\run 19
\Classes\WMSOnlineCountingServer\validateRun 3
\Classes\WMSOnlineCounting\validateRun 3
\Forms\WMSOnlineCounting\Methods\canClose 9
\Classes\FormRun\closeOk
After updating the quantity and clicking OK button the above trace log is generated.
It will update the quantity and financial dimension will update if settings exist on item or site. But, no journal number exist in counting journal.
Monday, June 25, 2018
Create a Translate button on new form in D365/Ax2012:
In standard we have translation in many places in D365. For example here I am showing in General Leger-Char of Accounts-Accounts-Main accounts.
Similarly, I have to develop the translation on another standard form called Questions as below:
Create a new table, class as below.
Table-KMQuestionTranslation. You need to write the table method. It is already there in the other standard Translation Tables.
Table properties as below:
Enjoy :)
Similarly, I have to develop the translation on another standard form called Questions as below:
Create a new table, class as below.
Table-KMQuestionTranslation. You need to write the table method. It is already there in the other standard Translation Tables.
Table properties as below:
Create a new class as below:
Write below code in Tables->KMQuestion->Insert():
Create a new Action Menu Item and add the menu item to the form extension as below:
Final project Area as below:
Finally, the translation added to the Question Form.
Enjoy :)
User Date Sequence in D365 and Ax2012:
The below method will return the date sequence automatically.
Instead of hard coding as 123 or 213
str2Date(DateValue,123);
use the below code.
static int userDateSequence()
{
int ds1, ds2, ds3;
date d = str2Date('2015/12/18', 321);
str s = strFmt('%1', d);
void datepart(str strDate, str dval, int part)
{
if (strEndsWith(strDate, dval))
ds3 = part;
else if (strStartsWith(strDate, dval))
ds1 = part;
else
ds2 = part;
}
datepart(s, '18', 1);
datepart(s, '12', 2);
datepart(s, '2015', 3);
return ds1 * 100 + ds2 * 10 + ds3;
}
Instead of hard coding as 123 or 213
str2Date(DateValue,123);
use the below code.
static int userDateSequence()
{
int ds1, ds2, ds3;
date d = str2Date('2015/12/18', 321);
str s = strFmt('%1', d);
void datepart(str strDate, str dval, int part)
{
if (strEndsWith(strDate, dval))
ds3 = part;
else if (strStartsWith(strDate, dval))
ds1 = part;
else
ds2 = part;
}
datepart(s, '18', 1);
datepart(s, '12', 2);
datepart(s, '2015', 3);
return ds1 * 100 + ds2 * 10 + ds3;
}
Wednesday, June 6, 2018
Add new field in the Trade Agreements journal lines "Standard Price" and update item purchase price using the batch job based on the conditions.
Add new field in the Trade Agreements journal lines "Standard Price" and update the item purchase price using the batch job based on the conditions.
Procurement and sourcing > Prices and
discounts > Trade agreement journals -> Create new PurchPrice trade
agreement journal and go to lines.
1. Add the New field -> PriceDiscAdmTrans.Extension (Table)
2. Create a SysOperatoin - Contract class:
[DataContractAttribute]
class PurchPriceDataContract
{
TransDate transDate;
str packedQuery;
[DataMemberAttribute ,SysOperationLabelAttribute(literalStr("@ABC:PurchTradeAgreementLabel"))]
public TransDate parmTransDate(TransDate _transDate = transDate)
{
transDate = _transDate;
return transDate;
}
[DataMemberAttribute, AifQueryTypeAttribute('_packedQuery', querystr(ItemPurchPrice))]
public str parmQuery(str _packedQuery = packedQuery)
{
packedQuery = _packedQuery;
return packedQuery;
}
public Query getQuery()
{
return new Query(SysOperationHelper::base64Decode(packedQuery));
}
public void setQuery(Query _query)
{
packedQuery = SysOperationHelper::base64Encode(_query.pack());
}
}
3. Created a Service class -
class PurchPriceDataService
{
QueryRun queryRun;
InventTable inventTable;
InventTableModule inventTableModule;
PriceConvertFactory priceConvertFactory;
PriceConvert priceConvert;
TransDate transDate;
PriceDiscAdmTrans priceDiscAdmTrans;
PriceDiscAdmTable priceDiscAdmTable;
PriceCur price;
PriceUnit priceUnit;
//
#ISOCountryRegionCodes
boolean countryRegion_RU;
//
[SysEntryPointAttribute]
public void updateItemPurchPrice(PurchPriceDataContract _purchPriceDataContract)
{
// Query objects
Query query;
QueryRun queryRunpriceDiscAdmTrans;
QueryBuildDataSource qbdspriceDiscAdmTrans;
QueryBuildDataSource qbdspriceDiscAdmTable;
QueryBuildRange qbrpriceDiscAdmTrans;
QueryBuildRange qbrpriceDiscAdmTable;
// create a new queryrun object
queryRun = new queryRun(ItemPurchPriceDataContract.getQuery());
// loop all results from the query
while(queryRun.next())
{
inventTable = queryRun.get(tableNum(InventTable));
transDate = _purchPriceDataContract.parmTransDate();
if(inventTable.PrimaryVendorId)
{
query = new query();
qbdspriceDiscAdmTable = query.addDataSource(tablenum(PriceDiscAdmTable));
qbrpriceDiscAdmTable = qbdspriceDiscAdmTable.addRange(fieldNum(PriceDiscAdmTable,DefaultRelation));
qbrpriceDiscAdmTable.value(enum2Str(PriceType::PricePurch));
qbrpriceDiscAdmTable = qbdspriceDiscAdmTable.addRange(fieldNum(PriceDiscAdmTable,Posted));
qbrpriceDiscAdmTable.value(enum2Str(NoYes::Yes));
qbdspriceDiscAdmTrans = qbdspriceDiscAdmTable.addDataSource(tablenum(PriceDiscAdmTrans));
qbdspriceDiscAdmTrans.addLink(fieldNum(PriceDiscAdmTable, JournalNum), fieldNum(PriceDiscAdmTrans, JournalNum));
qbrpriceDiscAdmTrans = qbdspriceDiscAdmTrans.addRange(fieldNum(PriceDiscAdmTrans, Relation));
qbrpriceDiscAdmTrans.value(enum2Str(PriceType::PricePurch));
qbrpriceDiscAdmTrans = qbdspriceDiscAdmTrans.addRange(fieldNum(PriceDiscAdmTrans, ItemRelation));
qbrpriceDiscAdmTrans.value(inventTable.itemId);
qbrpriceDiscAdmTrans = qbdspriceDiscAdmTrans.addRange(fieldNum(PriceDiscAdmTrans, FromDate));
qbrpriceDiscAdmTrans.value(SysQuery::range(transDate, dateNull()));
qbrpriceDiscAdmTrans = qbdspriceDiscAdmTrans.addRange(fieldNum(PriceDiscAdmTrans, ToDate));
qbrpriceDiscAdmTrans.value(SysQuery::range(dateNull(), transDate));
// Results sorting
qbdspriceDiscAdmTrans.addSortField(fieldNum(PriceDiscAdmTrans, StandardPurchPrice), SortOrder::Descending);
qbdspriceDiscAdmTrans.addSortField(fieldNum(PriceDiscAdmTrans, Amount), SortOrder::Descending);
qbdspriceDiscAdmTrans.firstOnly(true);
queryRunpriceDiscAdmTrans = new QueryRun(query);
if(queryRunpriceDiscAdmTrans.next())
{
priceDiscAdmTrans = queryRunpriceDiscAdmTrans.get(tableNum(PriceDiscAdmTrans));
inventTableModule = InventTableModule::find(inventTable.ItemId,ModuleInventPurchSales::Purch);
priceConvertFactory = PriceConvertFactory::newItemPrice(priceDiscAdmTrans.ItemRelation,
inventTableModule.UnitId,
priceDiscAdmTrans.Amount,//inventTableModule.price(),
inventTableModule.priceUnit(),
inventTableModule.markup(),
inventTableModule.priceQty(),
'',
countryRegion_RU ? inventTableModule.priceSecCur_RU() : 0,
countryRegion_RU ? inventTableModule.markupSecCur_RU() : 0);
priceConvertFactory.parmNewCurrencyCode(priceDiscAdmTrans.Currency);
priceConvertFactory.parmTransDate(transDate);
priceConvertFactory.parmNewUnitId(priceDiscAdmTrans.UnitId);
priceConvert = priceConvertFactory.priceConvert();
price = priceConvert.parmPrice();
ttsbegin;
inventTableModule.selectForUpdate(true);
inventTableModule.price = price;
inventTableModule.update();
ttscommit;
}
}
}
}
}
4. Create a AOT query for the contract class.
finally, update the price on the item purchase price where primary vendor is mentioned.
The above code will fetch the record from the trade agreements base on the dialog box itemID and date selection (which is a AOT Query) and then convert using the standard logic currency conversion, in case the company currency and trade agreements currency are different and then update the item purchase price.
Create Production Picking List Journal through code in D365:
The below class will create the production picking list journal header and lines through code based on the proposal and consumption quantity.
Let us assume for an item - Item001. The BOM proposal quantity = 5 and consumption quantity = 3 then the below code will create picking list journal for the production order - Item001- 3(qty).
In case the Production order has BOM lines more than 1 item then it will create for all the items.
//Create new picking list journal when difference between proposal and consumption on production order.
class ProdPickingListJourBOM
{
ProdJournalTable prodJournalTable;
ProdJournalBOM prodJournalBOM;
ProdBOMConsumpProposal consumpProposal;
BOMAutoConsump bomAutoConsump;
ProdBOM consumptionProdBOM;
NoYes consumpAsProposal;
NoYes proposalAsConsump;
NoYes drawNegative;
NoYes skipAccError;
NoYes endUpdate;
OprNum oprNumFrom;
OprNum oprNumTo;
InventQty qtyCalc;
BOMQty qtyConsumption;
boolean isStart;
boolean isFinish;// Reported as finished
ProdId prodId;
ProdJournalNameId journalNameId;
boolean createNoYes = false;
ProdJournalTable prodJournalOrig;
public void create(ProdJournalTable _prodJournalTable)
{
#OCCRetryCount
prodJournalOrig = _prodJournalTable;
try
{
ttsbegin;
this.initialValues();
if (! this.validate())
{
throw error("@SYS18447");
}
this.check();
if(createNoYes)
{
this.createHeader();
}
ttscommit;
}
catch (Exception::Deadlock)
{
retry;
}
catch (Exception::UpdateConflict)
{
if (appl.ttsLevel() == 0)
{
if (xSession::currentRetryCount() >= #RetryNum)
{
throw Exception::UpdateConflictNotRecovered;
}
else
{
retry;
}
}
else
{
throw Exception::UpdateConflict;
}
}
}
void initialValues()
{
oprNumTo = 0;
bomAutoConsump = BOMAutoConsump::Never;
consumpProposal = ProdBOMConsumpProposal::RemainQty;
consumpAsProposal = NoYes::Yes;
oprNumFrom = 0;
qtyCalc = 0;
endUpdate = NoYes::No;
prodId = prodJournalOrig.ProdId;
journalNameId = prodJournalOrig.JournalNameId;
}
boolean validate()
{
boolean ok = true;
if (!prodId)
{
ok = checkFailed("@SYS26122");
}
if (!ProdTable::checkExist(prodId))
{
ok = false;
}
if (! ProdTable::find(prodId).status().isBefore(ProdStatus::Completed))
{
ok = checkFailed(strfmt("@SYS22041",ProdTable::find(prodId).ProdStatus));
}
if (!journalNameId)
{
ok = checkFailed("@SYS26138");
}
if (!ProdJournalName::checkExist(journalNameId))
{
ok = false;
}
if (consumpProposal == ProdBOMConsumpProposal::Reversed)
{
ok = ok && ProdJournalBOM::checkNotMissingPosting(prodId);
}
ok = ok && this.checkCreateLinesProdBOM();
return ok;
}
boolean check()
{
ProdBOM prodBOM;
ProdJournalBOM prodJournalBomOrig;
BOMCalcData bomCalcData = BOMCalcData::newProdTable(qtyCalc,ProdTable::find(prodJournalOrig.ProdId));
while select forupdate prodBOM
index hint NumIdx
join prodJournalBomOrig
where prodBOM.ProdId == prodJournalOrig.ProdId
&& prodJournalBomOrig.JournalId == prodJournalOrig.JournalId
&& prodJournalBomOrig.InventTransId == prodBOM.InventTransId
{
ProdBOMCalc prodBOMCalc = ProdBOMCalc::newBOMCalcData(bomCalcData, prodBOM, consumpProposal, bomAutoConsump, !prodBOM.ConstantReleased, skipAccError, isStart, isFinish);
if (prodBOMCalc.bomConsump() || prodBOMCalc.bomProposal() || prodBOMCalc.inventConsump() || prodBOMCalc.inventProposal()
|| ((endUpdate
&& bomAutoConsump != BOMAutoConsump::FlushingPrincip || prodBOM.ProdFlushingPrincip != ProdFlushingPrincipBOM::Manual)
&& prodBOM.BackorderStatus == ProdBackStatus::Release))
{
createNoYes = true;
break;
}
}
return createNoYes;
}
boolean checkCreateLinesProdBOM()
{
boolean ret = true;
ProdBOM prodBOM;
//
ProdTable prodTable = ProdTable::find(prodId);
boolean isProjMethodConsumed = prodTable.isProjMethodConsumed();
boolean calculatingWIP_RU = prodTable.calculatingWIP_RU();
//
//
if (isProjMethodConsumed || calculatingWIP_RU)
//
{
while select prodBOM
index hint NumIdx
where prodBOM.ProdId == prodId
&& prodBOM.OprNum >= oprNumFrom
&& (prodBOM.OprNum <= oprNumTo || !oprNumTo)
{
//
setprefix(strfmt("@SYS24300", prodBOM.ItemId));
if (isProjMethodConsumed)
{
//
ret = ret && prodBOM.validateProject();
//
}
if (calculatingWIP_RU)
{
ret = ret && prodBOM.checkBOMQty_RU(true);
}
//
}
}
return ret;
}
public ProdJournalTable createHeader()
{
ProdTable prodTable = prodTable::find(prodJournalOrig.ProdId);
prodJournalTable.clear();
prodJournalTable.initValue();
prodJournalTable.JournalType = ProdJournalType::Picklist;
prodJournalTable.JournalNameId = prodJournalOrig.JournalNameId;
prodJournalTable.Description = prodJournalOrig.Description;
prodJournalTable.ProdId = prodTable.ProdId;
prodJournalTable.VoucherDraw = JournalVoucherDraw::Post;
prodJournalTable.VoucherSeqRecId = NumberSequenceTable::find(ProdParameters::numRefProdJournalVoucherId().NumberSequenceId).RecId;
if (!prodJournalTable.JournalId)
{
prodJournalTable.DrawNegative = drawNegative;
}
prodJournalTable.AutoCreateDiff = NoYes::Yes;
prodJournalTable.insert();
this.createLines();
prodJournalTable.selectForUpdate(true);
prodJournalTable.NumOfLines = ProdJournalBOM::lastLineNum(prodJournalTable.JournalId);
prodJournalTable.update();
return prodJournalTable;
}
public void createLines()
{
ProdBOM prodBOM;
ProdJournalBOM prodJournalBomOrig;
BOMCalcData bomCalcData = BOMCalcData::newProdTable(qtyCalc,ProdTable::find(prodJournalOrig.ProdId));
setPrefix("@SYS28536");
if (!oprNumTo)
{
oprNumTo = oprNumFrom;
}
while select forupdate prodBOM
index hint NumIdx
join prodJournalBomOrig
where prodBOM.ProdId == prodJournalOrig.ProdId
&& prodJournalBomOrig.JournalId == prodJournalOrig.JournalId
&& prodJournalBomOrig.InventTransId == prodBOM.InventTransId
&& prodBOM.OprNum >= oprNumFrom
&& (prodBOM.OprNum <= oprNumTo || !oprNumTo)
{
ProdBOMCalc prodBOMCalc = ProdBOMCalc::newBOMCalcData(bomCalcData, prodBOM, consumpProposal, bomAutoConsump, !prodBOM.ConstantReleased, skipAccError, isStart, isFinish);
this.createSingleLineProdBOM(prodBOM,
prodBOMCalc.bomConsump(),
prodBOMCalc.bomProposal(),
prodBOMCalc.inventConsump(),
prodBOMCalc.inventProposal(),
prodBOMCalc.pdsCWInventConsump(),
prodBOMCalc.pdsCWInventProposal());
}
}
public void createSingleLineProdBOM(
ProdBOM _prodBOM,
UnitQty _bomConsump,
UnitQty _bomProposal,
UnitQty _inventConsump,
UnitQty _inventProposal,
UnitQty _pdsCWInventConsump,
UnitQty _pdsCWInventProposal)
{
if (_bomConsump || _bomProposal || _inventConsump || _inventProposal
|| ((endUpdate
&& bomAutoConsump != BOMAutoConsump::FlushingPrincip || _prodBOM.ProdFlushingPrincip != ProdFlushingPrincipBOM::Manual)
&& _prodBOM.BackorderStatus == ProdBackStatus::Release))
{
prodJournalBOM.clear();
prodJournalBOM.initValue();
prodJournalBOM.JournalId = prodJournalTable.JournalId;
prodJournalBOM.initFromProdBOM(_prodBOM);
prodJournalBOM.EndConsump = endUpdate;
//
if (TaxParameters::isExciseEnable_IN())
{
TransTaxInformation transTaxInformation_Current;
TransTaxInformation transTaxInformation_Origin;
transTaxInformation_Current = TransTaxInformationHelper_IN::findOrCreateTransTaxInformation(prodJournalBOM.TableId, prodJournalBOM.RecId, true);
transTaxInformation_Origin = TransTaxInformationHelper_IN::findOrCreateTransTaxInformation(_prodBOM.prodTable().TableId, _prodBOM.prodTable().RecId);
transTaxInformation_Current.CompanyLocation = transTaxInformation_Origin.CompanyLocation;
transTaxInformation_Current.TaxInformation = transTaxInformation_Origin.TaxInformation;
TransTaxInformationHelper_IN::initFromTaxInformation(transTaxInformation_Current);
transTaxInformation_Current.ExciseType = ExciseType_IN::Manufacturer;
ttsbegin;
transTaxInformation_Current.doUpdate();
ttscommit;
}
//
prodJournalBOM.bomConsump = _bomConsump;
prodJournalBOM.bomProposal = _bomProposal;
prodJournalBOM.InventConsump = _inventConsump;
prodJournalBOM.InventProposal = _inventProposal;
prodJournalBOM.PdsCWInventConsump = _pdsCWInventConsump;
prodJournalBOM.PdsCWInventProposal= _pdsCWInventProposal;
if (consumpAsProposal)
{
prodJournalBOM.bomConsump = prodJournalBOM.bomProposal;
prodJournalBOM.InventConsump = prodJournalBOM.InventProposal;
prodJournalBOM.PdsCWInventConsump = prodJournalBOM.PdsCWInventProposal;
}
if (proposalAsConsump)
{
prodJournalBOM.bomProposal = prodJournalBOM.bomConsump;
prodJournalBOM.InventProposal = prodJournalBOM.InventConsump;
prodJournalBOM.PdsCWInventProposal = prodJournalBOM.PdsCWInventConsump;
}
prodJournalBOM.insert();
}
}
}
Let us assume for an item - Item001. The BOM proposal quantity = 5 and consumption quantity = 3 then the below code will create picking list journal for the production order - Item001- 3(qty).
In case the Production order has BOM lines more than 1 item then it will create for all the items.
//Create new picking list journal when difference between proposal and consumption on production order.
class ProdPickingListJourBOM
{
ProdJournalTable prodJournalTable;
ProdJournalBOM prodJournalBOM;
ProdBOMConsumpProposal consumpProposal;
BOMAutoConsump bomAutoConsump;
ProdBOM consumptionProdBOM;
NoYes consumpAsProposal;
NoYes proposalAsConsump;
NoYes drawNegative;
NoYes skipAccError;
NoYes endUpdate;
OprNum oprNumFrom;
OprNum oprNumTo;
InventQty qtyCalc;
BOMQty qtyConsumption;
boolean isStart;
boolean isFinish;// Reported as finished
ProdId prodId;
ProdJournalNameId journalNameId;
boolean createNoYes = false;
ProdJournalTable prodJournalOrig;
public void create(ProdJournalTable _prodJournalTable)
{
#OCCRetryCount
prodJournalOrig = _prodJournalTable;
try
{
ttsbegin;
this.initialValues();
if (! this.validate())
{
throw error("@SYS18447");
}
this.check();
if(createNoYes)
{
this.createHeader();
}
ttscommit;
}
catch (Exception::Deadlock)
{
retry;
}
catch (Exception::UpdateConflict)
{
if (appl.ttsLevel() == 0)
{
if (xSession::currentRetryCount() >= #RetryNum)
{
throw Exception::UpdateConflictNotRecovered;
}
else
{
retry;
}
}
else
{
throw Exception::UpdateConflict;
}
}
}
void initialValues()
{
oprNumTo = 0;
bomAutoConsump = BOMAutoConsump::Never;
consumpProposal = ProdBOMConsumpProposal::RemainQty;
consumpAsProposal = NoYes::Yes;
oprNumFrom = 0;
qtyCalc = 0;
endUpdate = NoYes::No;
prodId = prodJournalOrig.ProdId;
journalNameId = prodJournalOrig.JournalNameId;
}
boolean validate()
{
boolean ok = true;
if (!prodId)
{
ok = checkFailed("@SYS26122");
}
if (!ProdTable::checkExist(prodId))
{
ok = false;
}
if (! ProdTable::find(prodId).status().isBefore(ProdStatus::Completed))
{
ok = checkFailed(strfmt("@SYS22041",ProdTable::find(prodId).ProdStatus));
}
if (!journalNameId)
{
ok = checkFailed("@SYS26138");
}
if (!ProdJournalName::checkExist(journalNameId))
{
ok = false;
}
if (consumpProposal == ProdBOMConsumpProposal::Reversed)
{
ok = ok && ProdJournalBOM::checkNotMissingPosting(prodId);
}
ok = ok && this.checkCreateLinesProdBOM();
return ok;
}
boolean check()
{
ProdBOM prodBOM;
ProdJournalBOM prodJournalBomOrig;
BOMCalcData bomCalcData = BOMCalcData::newProdTable(qtyCalc,ProdTable::find(prodJournalOrig.ProdId));
while select forupdate prodBOM
index hint NumIdx
join prodJournalBomOrig
where prodBOM.ProdId == prodJournalOrig.ProdId
&& prodJournalBomOrig.JournalId == prodJournalOrig.JournalId
&& prodJournalBomOrig.InventTransId == prodBOM.InventTransId
{
ProdBOMCalc prodBOMCalc = ProdBOMCalc::newBOMCalcData(bomCalcData, prodBOM, consumpProposal, bomAutoConsump, !prodBOM.ConstantReleased, skipAccError, isStart, isFinish);
if (prodBOMCalc.bomConsump() || prodBOMCalc.bomProposal() || prodBOMCalc.inventConsump() || prodBOMCalc.inventProposal()
|| ((endUpdate
&& bomAutoConsump != BOMAutoConsump::FlushingPrincip || prodBOM.ProdFlushingPrincip != ProdFlushingPrincipBOM::Manual)
&& prodBOM.BackorderStatus == ProdBackStatus::Release))
{
createNoYes = true;
break;
}
}
return createNoYes;
}
boolean checkCreateLinesProdBOM()
{
boolean ret = true;
ProdBOM prodBOM;
//
ProdTable prodTable = ProdTable::find(prodId);
boolean isProjMethodConsumed = prodTable.isProjMethodConsumed();
boolean calculatingWIP_RU = prodTable.calculatingWIP_RU();
//
//
if (isProjMethodConsumed || calculatingWIP_RU)
//
{
while select prodBOM
index hint NumIdx
where prodBOM.ProdId == prodId
&& prodBOM.OprNum >= oprNumFrom
&& (prodBOM.OprNum <= oprNumTo || !oprNumTo)
{
//
setprefix(strfmt("@SYS24300", prodBOM.ItemId));
if (isProjMethodConsumed)
{
//
ret = ret && prodBOM.validateProject();
//
}
if (calculatingWIP_RU)
{
ret = ret && prodBOM.checkBOMQty_RU(true);
}
//
}
}
return ret;
}
public ProdJournalTable createHeader()
{
ProdTable prodTable = prodTable::find(prodJournalOrig.ProdId);
prodJournalTable.clear();
prodJournalTable.initValue();
prodJournalTable.JournalType = ProdJournalType::Picklist;
prodJournalTable.JournalNameId = prodJournalOrig.JournalNameId;
prodJournalTable.Description = prodJournalOrig.Description;
prodJournalTable.ProdId = prodTable.ProdId;
prodJournalTable.VoucherDraw = JournalVoucherDraw::Post;
prodJournalTable.VoucherSeqRecId = NumberSequenceTable::find(ProdParameters::numRefProdJournalVoucherId().NumberSequenceId).RecId;
if (!prodJournalTable.JournalId)
{
prodJournalTable.DrawNegative = drawNegative;
}
prodJournalTable.AutoCreateDiff = NoYes::Yes;
prodJournalTable.insert();
this.createLines();
prodJournalTable.selectForUpdate(true);
prodJournalTable.NumOfLines = ProdJournalBOM::lastLineNum(prodJournalTable.JournalId);
prodJournalTable.update();
return prodJournalTable;
}
public void createLines()
{
ProdBOM prodBOM;
ProdJournalBOM prodJournalBomOrig;
BOMCalcData bomCalcData = BOMCalcData::newProdTable(qtyCalc,ProdTable::find(prodJournalOrig.ProdId));
setPrefix("@SYS28536");
if (!oprNumTo)
{
oprNumTo = oprNumFrom;
}
while select forupdate prodBOM
index hint NumIdx
join prodJournalBomOrig
where prodBOM.ProdId == prodJournalOrig.ProdId
&& prodJournalBomOrig.JournalId == prodJournalOrig.JournalId
&& prodJournalBomOrig.InventTransId == prodBOM.InventTransId
&& prodBOM.OprNum >= oprNumFrom
&& (prodBOM.OprNum <= oprNumTo || !oprNumTo)
{
ProdBOMCalc prodBOMCalc = ProdBOMCalc::newBOMCalcData(bomCalcData, prodBOM, consumpProposal, bomAutoConsump, !prodBOM.ConstantReleased, skipAccError, isStart, isFinish);
this.createSingleLineProdBOM(prodBOM,
prodBOMCalc.bomConsump(),
prodBOMCalc.bomProposal(),
prodBOMCalc.inventConsump(),
prodBOMCalc.inventProposal(),
prodBOMCalc.pdsCWInventConsump(),
prodBOMCalc.pdsCWInventProposal());
}
}
public void createSingleLineProdBOM(
ProdBOM _prodBOM,
UnitQty _bomConsump,
UnitQty _bomProposal,
UnitQty _inventConsump,
UnitQty _inventProposal,
UnitQty _pdsCWInventConsump,
UnitQty _pdsCWInventProposal)
{
if (_bomConsump || _bomProposal || _inventConsump || _inventProposal
|| ((endUpdate
&& bomAutoConsump != BOMAutoConsump::FlushingPrincip || _prodBOM.ProdFlushingPrincip != ProdFlushingPrincipBOM::Manual)
&& _prodBOM.BackorderStatus == ProdBackStatus::Release))
{
prodJournalBOM.clear();
prodJournalBOM.initValue();
prodJournalBOM.JournalId = prodJournalTable.JournalId;
prodJournalBOM.initFromProdBOM(_prodBOM);
prodJournalBOM.EndConsump = endUpdate;
//
if (TaxParameters::isExciseEnable_IN())
{
TransTaxInformation transTaxInformation_Current;
TransTaxInformation transTaxInformation_Origin;
transTaxInformation_Current = TransTaxInformationHelper_IN::findOrCreateTransTaxInformation(prodJournalBOM.TableId, prodJournalBOM.RecId, true);
transTaxInformation_Origin = TransTaxInformationHelper_IN::findOrCreateTransTaxInformation(_prodBOM.prodTable().TableId, _prodBOM.prodTable().RecId);
transTaxInformation_Current.CompanyLocation = transTaxInformation_Origin.CompanyLocation;
transTaxInformation_Current.TaxInformation = transTaxInformation_Origin.TaxInformation;
TransTaxInformationHelper_IN::initFromTaxInformation(transTaxInformation_Current);
transTaxInformation_Current.ExciseType = ExciseType_IN::Manufacturer;
ttsbegin;
transTaxInformation_Current.doUpdate();
ttscommit;
}
//
prodJournalBOM.bomConsump = _bomConsump;
prodJournalBOM.bomProposal = _bomProposal;
prodJournalBOM.InventConsump = _inventConsump;
prodJournalBOM.InventProposal = _inventProposal;
prodJournalBOM.PdsCWInventConsump = _pdsCWInventConsump;
prodJournalBOM.PdsCWInventProposal= _pdsCWInventProposal;
if (consumpAsProposal)
{
prodJournalBOM.bomConsump = prodJournalBOM.bomProposal;
prodJournalBOM.InventConsump = prodJournalBOM.InventProposal;
prodJournalBOM.PdsCWInventConsump = prodJournalBOM.PdsCWInventProposal;
}
if (proposalAsConsump)
{
prodJournalBOM.bomProposal = prodJournalBOM.bomConsump;
prodJournalBOM.InventProposal = prodJournalBOM.InventConsump;
prodJournalBOM.PdsCWInventProposal = prodJournalBOM.PdsCWInventConsump;
}
prodJournalBOM.insert();
}
}
}
Subscribe to:
Posts (Atom)
