Wednesday 20 November 2019

Fetch different data source value in a Display method in D365 FO

Hi All,
Some time we have to fetch more than 1 data source value of a form in a display method in D365 FO, but the problem is we can pass only 1 data source buffer in the display method, so to overcome this have a look to the below code, in the example I am fetching the InventDim table buffer from the inventDim dataSource of the form.



[ExtensionOf(tableStr(InventDimCombination))]
final public class InventDimCombinationTbl_Extension
{
    public static display InventQtyAvailPhysical displayAvailSupplyQty(InventDimCombination _this)
    {
        InventDim            inventDimFind;
        InventSum            inventSumLocal;
        InventDimParm   inventDimParmLocal;
       
        FormDataSource  inventDimCombination_ds = _this.datasource();
        FormDataSource  inventDim_ds   = inventDimCombination_ds.formRun().dataSource("InventDim");
        InventDim    inventDim  = inventDim_ds.cursor();
       
        inventDimFind.initFromInventDim(inventDim);
        EcoResProductDimGroupSetup::copyProductDimensionsForItem(_this.ItemId, _this.inventDim(), inventDimFind);

        inventDimParmLocal.ItemIdFlag             = NoYes::Yes;
        inventDimParmLocal.InventStatusFlag  = NoYes::Yes;
        inventDimParmLocal.setActiveSiteAndWarehouseDimensions();

        inventDimParmLocal.setActiveProductDim(EcoResProductDimGroupSetup::newItemId(_this.ItemId));

        inventSumLocal = InventSum::findSumQty(_this.ItemId, inventDimFind, inventDimParmLocal);

        return inventSumLocal.AvailPhysical;

    }
 }

In this way we can find any datasource value which is linked to a form in a display method


Tuesday 4 June 2019

Get duplicate line number based on search criteria in a table.

ImportStagingLine stagingLine1;
ImportStagingLine stagingLine2;
str               numberOfLines;
str               strToScan;
boolean           ret = true;
  

while select Recid, LineNum from stagingLine1
order by lineNum
join Recid, LineNum from stagingLine2
order by lineNum
where stagingLine2.ItemId == stagingLine1.ItemId
&& stagingLine2.InventSizeIdColour == stagingLine1.InventSizeIdColour

&& stagingLine2.AccountCode == stagingLine1.AccountCode

&& stagingLine2.AccountRelation == stagingLine1.AccountRelation

&& stagingLine2.MarkDownFromDate == stagingLine1.MarkDownFromDate

&& stagingLine2.Currency == stagingLine1.Currency

&& stagingLine2.PriceType == stagingLine1.PriceType

&& stagingLine2.RecId != stagingLine1.RecId

&& stagingLine2.StagingHeaderRefRecId == stagingLine1.StagingHeaderRefRecId

&& stagingLine1.StagingHeaderRefRecId == _refRecId

{

strToScan = strMin();
strToScan = strFmt("%1", stagingLine1.LineNum);


if (strScan(numberOfLines, strToScan, 1, strLen(numberOfLines)) == 0)
{
    numberOfLines += strFmt("%1-%2, %3", stagingLine1.LineNum, stagingLine2.LineNum, strMin()); }



ret = false; }


numberOfLines = strDel(numberOfLines, strLen(numberOfLines) -1, 3);

if (ret == false)
{
checkFailed(strFmt("For header record: %1 the line number: %2 are identical.", _refRecId, numberOfLines)); }



 

Insert/Update or remove the default dimension value in D365 FSCM via x++

Use below method to insert/update the dimension values, just pass the parameter values to the method and it will return the updated value: p...