Tag Archives: Finance and Operations

D365/AX7: Calculate On Hand Stock Of Item Using X++ & Code

public static void main(Args _args)
{
InventDimParm inventDimParm;
InventDim inventDim; 
Qty availPhysicalCalculated; ;
inventDim.InventLocationId = 'MLT-WH';
inventDim = InventDim::findOrCreate(inventDim);
inventDimParm.initFromInventDim(InventDim::find(inventDim.inventDimId));
availPhysicalCalculated = InventSum::findSum("ALLOY",inventDim,inventDimParm).availPhysicalCalculated();
info(strfmt("availPhys:%1 ",availPhysicalCalculated));
}

D365/AX7: X++ Code To Create Item or Released Product Using Data Entity EcoResReleasedProductCreationV2Entity

Requirement

X++ Code To Create Item or Released Production Using Data Entity EcoResReleasedProductCreationV2Entity

Sample Code

class CreateReleasedProduct
{ 
/// <summary>
/// Runs the class with the specified arguments.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{ 
EcoResReleasedProductCreationV2Entity ecoResReleasedProductCreationV2Entity;
;

ecoResReleasedProductCreationV2Entity.clear();
ecoResReleasedProductCreationV2Entity.initValue();
ecoResReleasedProductCreationV2Entity.ItemNumber = '1104X';
ecoResReleasedProductCreationV2Entity.ItemModelGroupId = 'Stocked';
ecoResReleasedProductCreationV2Entity.InventoryUnitSymbol = 'ea';
ecoResReleasedProductCreationV2Entity.BOMUnitSymbol = 'ea';
ecoResReleasedProductCreationV2Entity.ProductGroupId = 'FG';
ecoResReleasedProductCreationV2Entity.ProductType = EcoResProductType::Item;
ecoResReleasedProductCreationV2Entity.ProductNumber = '1104X';
ecoResReleasedProductCreationV2Entity.ProductSearchName = '1104X';
ecoResReleasedProductCreationV2Entity.ProductName = '1104X';
ecoResReleasedProductCreationV2Entity.TrackingDimensionGroupName = 'None';
ecoResReleasedProductCreationV2Entity.ProductSubType = EcoResProductSubtype::Product;
ecoResReleasedProductCreationV2Entity.SearchName = '1104X';
ecoResReleasedProductCreationV2Entity.SalesUnitSymbol = 'ea';
ecoResReleasedProductCreationV2Entity.StorageDimensionGroupName = 'SiteWH';
ecoResReleasedProductCreationV2Entity.PurchaseUnitSymbol = 'ea';
ecoResReleasedProductCreationV2Entity.insert();

}

}

D365/AX7: Inventory Registration & Un-Registration Using X++ Class InventTransWMS_register

Hey Visitors,

Here is the sample code for Inventory Registration & Un-Registration Using X++ Class InventTransWMS_register.

cheers,

piyush adhikari – +91-7995802472

public static void operations(PurchId _purchId)
{
PurchLine purchLine;
InventTrans inventTrans;
InventDim inventDim;
InventTransWMS_Register inventTransWMS_register;
TmpInventTransWMS tmpInventTransWMS;
;

ttsbegin;
while select RecId, InventTransId from purchLine
where purchLine.PurchId == _purchId
&& purchLine.IsDeleted == NoYes::No
&& purchLine.PurchQty > 0
{
inventTrans = InventTrans::findTransId(purchLine.InventTransId);
if(inventTrans && inventTrans.StatusReceipt != StatusReceipt::Registered)
{
inventDim = inventTrans.inventDim();
tmpInventTransWMS.clear();
tmpInventTransWMS.initFromInventTrans(inventTrans);
tmpInventTransWMS.InventQty = inventTrans.Qty;
tmpInventTransWMS.InventDimId = inventDim.inventDimId;
tmpInventTransWMS.insert();

inventTransWMS_register = inventTransWMS_register::newStandard(tmpInventTransWMS);
inventTransWMS_Register.createFromInventTrans(inventTrans, inventDim);
inventTransWMS_register.writeTmpInventTransWMS(tmpInventTransWMS, inventTrans, inventDim);
inventTransWMS_register.updateInvent(inventTrans);
}
}
ttscommit;
}



D365/AX7: Create A Batch Job Using SysOperation Framwork

  1. Create a data contract class  
    
    [DataContract]
    class AcxSysOperationContract
    { 
    PurchId purchId; 
    [DataMemberAttribute("PurchId")]
    public PurchId parmpurchId(PurchId _purchId = purchId)
    {
    purchId = _purchId;
    return _purchId;
    }
    
    }
  2. Create a service class where you will place your custom business logic
    
    class AcxSysOperationService
    {
    public void operation(AcxSysOperationContract _dataContract)
    {
    info(_dataContract.parmpurchId());
    //your business logic
    }
    
    }
  3. Create a controller class
    
    class AcxSysOperationController extends SysOperationServiceController
    {
    public static void main(Args args)
    {
    AcxSysOperationController sysOperationController = new AcxSysOperationController();
    sysOperationController.parmClassName(classStr(AcxSysOperationService));
    sysOperationController.parmMethodName(methodStr(AcxSysOperationService, operation));
    sysOperationController.parmExecutionMode(SysOperationExecutionMode::Synchronous);
    sysOperationController.startOperation();
    }
    
    }

D365/AX7:Get Parameters (DataEntityRuntimeContext/DataEntityRuntimeContext) in Data Entity Events

[DataEventHandler(tableStr(AcxBrandEntity), DataEventType::MappingEntityToDataSource)]
public static void AcxBrandEntity_onMappingEntityToDataSource(Common _sender, DataEventArgs _eventArgs)
{
DataEntityContextEventArgs dataEntityContextEventArgs = _eventArgs;
DataEntityRuntimeContext runtimeContext = dataEntityContextEventArgs.parmEntityContext();
DataEntityDataSourceRuntimeContext DataEntityDataSourceRuntimeContext = dataEntityContextEventArgs.parmEntityDataSourceContext();

}

Get Parameters (DataEntityRuntimeContext/DataEntityRuntimeContext) in Data Entity Events

D365/AX7: Create Repeated Header In Header Line Data Entity (Bypass Insert of Data Entity Header Table)

D365/AX7: Create Repeated Header In Header Line Data Entity (Bypass Insert of Data Entity Header Table)

_dataSourceCtx.setBuffer(retailTransctionTableLocal);
_dataSourceCtx.setDataSaved(true);
_dataSourceCtx.setDatabaseOperation(DataEntityDatabaseOperation::Update);

D365/AX7: Multi Select LookUp In Form Grid (SysLookupMultiSelectGrid)

Requirement

Multi Select Lookup Of Warehouse In Form Grid.

Untitled

Sample Code

  1. Create a new Class AcxSysLookupMultiSelectGrid & extend it from SysLookupMultiSelectGrid.class AcxSysLookupMultiSelectGrid extends SysLookupMultiSelectGrid
    {
    #Characters
    public void setSelected()
    {
    dictfield dictField;
    Common currentDSRecord;
    FormDataSource formdatasource;
    callingControlId.text(SysOperationHelper::convertMultiSelectedValueString(selectedId));
    formdatasource = callingControlId.dataSourceObject();
    if(formdatasource && callingControlStr.dataField())
    {
    dictfield = new dictfield(formdatasource.table(),callingControlStr.dataField());
    currentDSRecord = formdatasource.cursor();
    currentDSRecord.(dictfield.id()) = currentDSRecord.(dictfield.id()) + SysOperationHelper::convertMultiSelectedValueString(selectedStr);
    callingControlStr.update();
    }
    else
    {
    callingControlStr.text(SysOperationHelper::convertMultiSelectedValueString(selectedStr));
    }
    }

    public static AcxSysLookupMultiSelectGrid construct(FormControl _ctrlId,
    FormControl _ctrlStr)
    {
    AcxSysLookupMultiSelectGrid lookupMS;
    lookupMS = new AcxSysLookupMultiSelectGrid ();
    lookupMS.parmCallingControlId(_ctrlId);
    lookupMS.parmCallingControlStr(_ctrlStr);
    return lookupMS;
    }

    }

  2. Override the Lookup() method of form control.
    public void lookup() {
    AcxUserSetup.InventlocationMulti = ”;
    multiSelectGrid = AcxSysLookupMultiSelectGrid ::construct(AcxUserSetup_InventlocationMulti,AcxUserSetup_InventlocationMulti);
    Query query = new Query();
    QueryBuildDataSource queryBuildDataSource;
    queryBuildDataSource = query.addDataSource(tableNum(InventLocation));
    queryBuildDataSource.addSelectionField(fieldNum(InventLocation, InventLocationId));
    queryBuildDataSource.addSelectionField(fieldNum(InventLocation, Name));
    multiSelectGrid.parmQuery(query);
    multiSelectGrid.parmCallingControl(this);
    multiSelectGrid.run();

    //super();
    }

 

D365/AX7: Method to call when record is marked – markChanged() FormDataSource

Requirement:

The requirement was to display information of selected records of form Grid on a string control.The information on custom string control should change during the marking of records in real time.

Sample Code:

Copy the method in form datasource.

  1. public void markChanged()
  2.         {
  3.             AcxBrandMaster  acxBrandMaster1;
  4.             str brandStr;
  5.             MultiSelectionHelper    multiSelectionHelper =  MultiSelectionHelper::construct();
  6.             multiSelectionHelper.parmDatasource(AcxBrandMaster_DS);
  7.             acxBrandMaster1 = multiSelectionHelper.getFirst();
  8.             FormStringControl1.text(“”);
  9.             while (acxBrandMaster1.RecId)
  10.             {
  11.                 brandStr = brandStr +  acxBrandMaster1.Brand;
  12.                 acxBrandMaster1 = multiSelectionHelper.getNext();
  13.             }
  14.             FormStringControl1.text(brandStr) ;
  15.             super();
  16.         }

D365/AX7: Using SysReferenceTableLookup For Reference Group In Form (Missing LookUpReference Event)

Requirement

Vendor Address Lookup in purchase order creation form (PurchCreateOrder).

Sample Code

For simple form control, we can use SysTableLookUp class & write code in onlookup event of form control.The sample code is mentioned in below line:

D365/AX7: Extend Form Control OnLookup Event On Standard Form

But for reference group control in form, SysTableLookup doesnot work.There is  one different class called  SysReferenceTableLookup For Reference Group In Form.Also in D365 there is no event related LookUpReference method.So i am using OnLookup event.

class AcxPurchCreateOrderFormEvents
{
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[FormControlEventHandler(formControlStr(PurchCreateOrder, PurchTable_AcxDeliveryPostalAddressVend), FormControlEventType::Lookup)]
public static void PurchTable_AcxDeliveryPostalAddressVend_OnLookup(FormControl sender, FormControlEventArgs e)
{
VendTable vendTable;
Common common;
PurchTable purchTable = sender.formRun().dataSource(formDataSourceStr(PurchCreateOrder,PurchTable )).cursor();
VendTable = VendTable::find(purchTable.OrderAccount);

SysReferenceTableLookup sysTableLookup = SysReferenceTableLookup ::newParameters(tableNum(LogisticsPostalAddress),sender);
Query q = new Query();
QueryBuildDataSource qbds;
qbds = q.addDataSource(tableNum(LogisticsPostalAddress));
sysTableLookup.addLookupfield(fieldNum(LogisticsPostalAddress, Location));
sysTableLookup.addLookupfield(fieldNum(LogisticsPostalAddress, Address));
sysTableLookup.parmQuery(q);
sysTableLookup.performFormLookup();
FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;
ce.CancelSuperCall();
}

}