Enter the key words to find the related topics

Invent dim buffer based on InventDimCombination and InventLocation values

Below method is used to get Invetdim records for item based on color,size,warehouse and site.


Example sales line item.



/// <summary>
/// Global class to include method for returning invent dim buffer based on InventDimCombination and InventLocation values
/// </summary>
class InventDimDefault
{

    /// <summary>
    /// class method to accept the parameter and return inventory dimenesion buffer.
    /// </summary>
    public static InventDim InventDimFunction(InventDimCombination _inventDimComb,InventLocation _inventLocation)
    {
        InventParameters                    inventParameter;
        InventDim                           inventDimLoc,inventDimDefault;     
        WMSLocationId                       defaultLocation;
        WHSInventStatusId                   defaultInventoryStatus;
        InventTable                         inventTable;
        InventDimParm                       inventDimParm;     

        select firstonly DefaultLocation,DefaultInventoryStatus from  inventParameter;

        inventTable   = InventTable::find(_inventDimComb.ItemId);
        inventDimParm =  InventDimParm::activeDimFlag(InventDimGroupSetup::newInventTable(inventTable));

        if(inventDimParm.InventSiteIdFlag && inventDimParm.InventLocationIdFlag && inventDimParm.InventStatusFlag && inventDimParm.WMSLocationIdFlag)
        {
            defaultLocation = inventParameter.DefaultLocation;
            defaultInventoryStatus = inventParameter.DefaultInventoryStatus;
        }
        else if(inventDimParm.InventSiteIdFlag && inventDimParm.InventLocationIdFlag && inventDimParm.WMSLocationIdFlag)
        {
            defaultLocation = inventParameter.DefaultLocation;
            defaultInventoryStatus = '';
        }
        else if(inventDimParm.InventSiteIdFlag && inventDimParm.InventLocationIdFlag && inventDimParm.InventStatusFlag)
        {
            defaultLocation = '';
            defaultInventoryStatus = inventParameter.DefaultInventoryStatus;
        }
        else if( inventDimParm.InventSiteIdFlag && inventDimParm.InventLocationIdFlag)
        {
            defaultLocation = '';
            defaultInventoryStatus = '';
        }

        inventDimDefault = InventDim::find(_inventDimComb.inventDimId);

        select inventDimLoc where inventDimLoc.InventSiteId == _inventLocation.InventSiteId && inventDimLoc.InventLocationId == _inventLocation.InventLocationId
                    && inventDimLoc.InventColorId == inventDimDefault.InventColorId && inventDimLoc.InventStyleId == inventDimDefault.InventStyleId
                    && inventDimLoc.InventSizeId == inventDimDefault.InventSizeId && inventDimLoc.configId == inventDimDefault.configId
                    && inventDimLoc.inventBatchId == inventDimDefault.inventBatchId && inventDimLoc.inventSerialId == inventDimDefault.inventSerialId
                    && inventDimLoc.wMSPalletId == inventDimDefault.wMSPalletId && inventDimLoc.LicensePlateId == inventDimDefault.LicensePlateId && inventDimLoc.wMSLocationId == defaultLocation
                    && inventDimLoc.InventStatusId == defaultInventoryStatus;
        if(!inventDimLoc.RecId)
        {
            inventDimLoc.clear();
            inventDimLoc.InventSiteId = _inventLocation.InventSiteId;
            inventDimLoc.InventLocationId = _inventLocation.InventLocationId;
            inventDimLoc.InventColorId = inventDimDefault.InventColorId;
            inventDimLoc.InventStyleId = inventDimDefault.InventStyleId;
            inventDimLoc.InventSizeId = inventDimDefault.InventSizeId ;
            inventDimLoc.configId = inventDimDefault.configId;
            inventDimLoc.inventBatchId = inventDimDefault.inventBatchId ;
            inventDimLoc.inventSerialId = inventDimDefault.inventSerialId;
            inventDimLoc.wMSPalletId = inventDimDefault.wMSPalletId;
            inventDimLoc.LicensePlateId = inventDimDefault.LicensePlateId;
            inventDimLoc.wMSLocationId = defaultLocation;
            inventDimLoc.InventStatusId = defaultInventoryStatus;
        }

        inventDimLoc = InventDim::findOrCreate(inventDimLoc);
        return inventDimLoc;
    }

}

D365 Table Event handler

DataEventType::Inserting 

[DataEventHandler(tableStr(PurchLine), DataEventType::Inserting)]
    public static void PurchLine_onInserting(Common sender, DataEventArgs e)
    {
        PurchLine purchLine = sender as PurchLine;

        if (InventTable::find(purchLine.ItemId).TrackingNum)
        {
            purchLine.TrackNumber =  purchLine.VendAccount + purchLine.PurchId;
        }
    }

DataEventType::Updating

 [DataEventHandler(tableStr(PurchLine), DataEventType::Updating)]
    public static void PurchLine_onUpdating(Common sender, DataEventArgs e)
    {
        PurchLine purchLine = sender as PurchLine;
        if (InventTable::find(purchLine.ItemId).TrackingNum)
        {
            purchLine.TrackNumber =  purchLine.VendAccount + purchLine.PurchId;
        }
        else
        {
            purchLine.TrackNumber =  #EmptyString;
        }
    }

DataEventType::Inserted

 [DataEventHandler(tableStr(RetailCustAffiliation), DataEventType::Inserted)]
    public static void RetailCustAffiliation_onInserted(Common sender, DataEventArgs e)
    {
        RetailCustAffiliation retailCustAffiliation = sender;
        if (retailCustAffiliation.CustAccountNum)
}



D365 Form Event Handler

FormControlEventType::Clicked

[FormControlEventHandler(formControlStr(CustOpenTrans, MarkOrderTotal), FormControlEventType::Clicked),

 public static void MarkOrderTotal_OnClicked(FormControl sender, FormControlEventArgs e)
{
        FormRun                     formRun = sender.formRun() as FormRun;
        FormRun                     formRunParent = formRun.args().caller();
        Common                      originator = formRun.args().record();
        FormDataSource         custTransOpen_ds = formRun.dataSource('CustTransOpen');
       CustTransOpen            custTransOpen = custTransOpen_ds.cursor();

}

FormControlEventType::Lookup

    [FormControlEventHandler(formControlStr(SalesTable, SalesLine_TruckShipmentId), FormControlEventType::Lookup),
    SuppressBPWarning('BPParameterNotUsed', 'Parameter required for eventhandler.')]
    public static void SalesLine_TruckShipmentId_OnLookup(FormControl sender, FormControlEventArgs e)
{
      SalesLine               salesLine = sender.dataSourceObject().cursor();
}

FormDataSourceEventType::Activated 

[FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesLine), FormDataSourceEventType::Activated),
    SuppressBPWarning('BPParameterNotUsed', 'Parameter required for eventhandler.')]
    public static void SalesLine_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
{
           SalesLine                   salesLine;


           salesLine = sender.cursor();

}

[FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesTable), FormDataSourceEventType::Activated) ]
    public static void SalesTable_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
    {
        FormRun formRun  = sender.formRun();
        SalesTable saleTable;
   
        FormDataSource salesTableDS    = formRun.dataSource(formDataSourceStr(SalesTable, SalesTable)) as FormDataSource;
        saleTable = salesTableDS.cursor();
}

FormDataFieldEventType::Modified

 [FormDataFieldEventHandler(formDataFieldStr(SalesTable, SalesLine, DlvMode), FormDataFieldEventType::Modified)]
    public static void DlvMode_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
{
        SalesLine                   salesLine;

        salesLine = sender.datasource().cursor();
}

Form field mandatory

 [FormDataFieldEventHandler(formDataFieldStr(SalesTable, FreightThirdPartyBilling, FreightBillAccount), FormDataFieldEventType::Modified) ]
    public static void FreightBillAccount_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
{
        FormDataSource                  thirdPartyBillingDS;
        FreightThirdPartyBilling     thirdPartyBilling;
        boolean                                 allowEdit;
        FormStringControl               cityCtrl;         
     
        thirdPartyBillingDS = sender.datasource();
        thirdPartyBilling = sender.datasource().cursor();
     
        cityCtrl = thirdPartyBillingDS.formRun().design().controlName(formControlStr(SalesTable,FreightThirdPartyBilling_City));
        cityCtrl.mandatory(allowEdit);
     
}


Form field modified and inserting into fields based on record.

 [FormDataFieldEventHandler(formDataFieldStr(PurchTable, PurchTable, VendFactoryAddress), FormDataFieldEventType::Modified)]
    public static void VendFactoryAddress_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
    {
        LogisticsPostalAddress    logisticsPostalAddress;
        int64                               factoryAdress;

        factoryAdress      = sender.getValue();
   
        select firstonly logisticsPostalAddress where logisticsPostalAddress.RecId == factoryAdress;
        sender.datasource().object(fieldNum(PurchTable, CountryRegId)).setValue(logisticsPostalAddress.CountryRegionId);
        sender.datasource().object(fieldNum(PurchTable, TransactionCode)).setValue(logisticsPostalAddress.TransactionCode);
        sender.datasource().object(fieldNum(PurchTable, Port)).setValue(logisticsPostalAddress.PortId);
        sender.datasource().object(fieldNum(PurchTable, IntermediaryCode)).setValue(logisticsPostalAddress.IntermediaryCode);

     
    }

Form method Post event Handler

[PostHandlerFor(formStr(SalesTable), formMethodStr(SalesTable, enableTMSFields))]
    public static void SalesTable_Post_enableTMSFields(XppPrePostArgs args)
 {
        FormRun salesTableForm  = args.getThis();
        Common common = salesTableForm.args().record();
       SalesTable  salesTab;
 FormStringControl   carrierCode  = salesTableForm.design(0).controlName(formControlStr(SalesTable, TMSSalesTable_CarrierCode));

        FormDataSource tmsSalesTableDatasource    = salesTableForm.dataSource(formDataSourceStr(SalesTable, TMSSalesTable)) as FormDataSource;
salesTab = salesTableDS.cursor();
}

FormDataSourceEventType::SelectionChanged

[FormDataSourceEventHandler(formDataSourceStr(LogisticsPostalAddressGrid, DirPartyPostalAddressView), FormDataSourceEventType::SelectionChanged)]
    public static void DirPartyPostalAddressView_OnSelectionChanged(FormDataSource sender, FormDataSourceEventArgs e)
    {
        var formRun = sender.formRun() as FormRun;
        str callerFormName = formRun.args().caller().Name();

        if(callerFormName == formStr(Decorator)) 
        {
            var dirPartyPostalAddDatasource = formRun.dataSource(formDataSourceStr(LogisticsPostalAddressGrid, DirPartyPostalAddressView)) as FormDataSource;
            if( dirPartyPostalAddDatasource.numberOfRowsLoaded() > 0 )
            {
                formRun.control(FormRun.controlId(formControlStr(LogisticsPostalAddressGrid, NewAddress))).enabled(false);
                formRun.control(FormRun.controlId(formControlStr(LogisticsPostalAddressGrid, MoreOptions))).enabled(false);
            }
            else
            {
                formRun.control(FormRun.controlId(formControlStr(LogisticsPostalAddressGrid, NewAddress))).enabled(true);
                formRun.control(FormRun.controlId(formControlStr(LogisticsPostalAddressGrid, MoreOptions))).enabled(true);
            }
        }
    }



D365 Best practice warring

If we get BP warring regarding parameter "e" is not used in coding part we can set below attribute in the method.

SuppressBPWarning('BPParameterNotUsed', 'Parametr e not used')

Example:
 [DataEventHandler(tableStr(PurchLine), DataEventType::Updating),
     SuppressBPWarning('BPParameterNotUsed', 'Parameter required for eventhandler.')]
    public static void PurchLine_onUpdating(Common sender, DataEventArgs e)
    {
}

D365 database Sync error convention failed from int to Real

Select the effected table for example salestable, one field in changed from int to real.
After changing the filed we may get an errors  cannot convert from int to Real.

Solution:

Go to Data base execute the below queries.

select * from salestable.// Check the data

select * into salestable_copy from salesTable. // This will copy the data from Salestable to salestable_copy

sp_removable salestable  // this will delete the table from entire data base.

select * into salesTable from salestable_copy  //This will copy the data from salestable_copy to Salestable 

Now we can delete the copy table as shown below.
sp_removable salestable_copy

sp_helptext salesTable // For stored procedure query.