Wednesday, June 30, 2021

Get Customer\Vendor account from LedgerDimension in D365FO using X++

 Get Customer\Vendor account from LedgerDimension in D365FO using X++.

Here is the simple code to get the customer\Vendor account number from the ledger Dimension.

if (LedgerJournalTrans.AccountType == LedgerJournalACType::vend)
{

VenAccount  VendAccount = LedgerDynamicAccountHelper::getAccountNumberFromDynamicAccount(LedgerDimension);

}

Keep Daxing!!

Friday, June 11, 2021

JSON CREATION & SERIALIZATION USING FORMJSONSERIALIZER In D365Fo using X++

 JSON CREATION & SERIALIZATION USING FORMJSONSERIALIZER In D365Fo using X++.

This is used in custom service. Below are different examples.


 Example 1:

Here I am passing the external item and qty data to update the stock on hand in D365fo.

Inputs from JSON. Operation is done in D365FO and returns the message like success / failed.

Create a service class and add the below methods.

[AifCollectionType('record', Types::Class, classStr(TestDataContract))]
public str updateStockOnHand(List record)
{
    str                     jsread;
    TestInventTable         testInventTable,testInventTableUpd;
    CustVendExternalItem    custVendExternalItem;
    ListEnumerator          lEnum = record.getEnumerator();
    ;

    while (lEnum.MoveNext())
    {
        try
        {
            TestDataContract        recordsContract = lEnum.current();
            ExtCodevalueTable       extCodevalueTable;
            InventDimCombination    inventdimcombination;
            InventItemBarcode       inventItemBarcode;
            str                     extTableName    = 'InventDimCombination';
            str                     extitemid       = recordsContract.externalCode();
            real                    qty             = recordsContract.qty();

            extCodevalueTable       = ExtCodeValueTable::findValue(tableName2Id(extTableName), 
                                            ExtCodeSubModule::None,_extCodeCode,extitemid);
            inventdimcombination    = InventDimCombination::findRecId(
                                            extCodevalueTable.ExtCodeRelationRecId);
            select firstonly forupdate testInventTable
                where testInventTable.ExternalItemId == extitemid
                    && testInventTable.Active == NoYes::Yes;

            if(testInventTable)
            {
                ttsbegin;

                testInventTable.Qty = qty;
                testInventTable.update();

                ttscommit;

                jsread += strFmt("%1, %2", extitemid,
                        "Is updated succesfully");
            }
            else
            {
                jsread += strFmt("%1:%2", extitemid,
                        "vendor part number is not exists or it is not active.");
            }
        }
        catch
        {
            jsread += strFmt("%1",infolog.text());

            continue;
        }
    }
    //   jsread = FormJsonSerializer::serializeClass(lEnum);

    return jsread;
}

        

Output.


Contract class:

//[DataContractAttribute,Newtonsoft.Json.JsonObject(IsReference = false)] -- remove Id value.

[DataContractAttribute]

public class TestDataContract 

{

    str itemId;

    real qty;

    [DataMemberAttribute('qty')]

    public real qty(real _qty = qty)

    {

        qty = _qty;

        return qty;

    }

    [DataMemberAttribute('External code')]

    public str externalCode(str _externalCode = externalCode)

    {

        externalCode = _externalCode;

        return externalCode;

    }

}


=========================================================================

 Example 2:

Here I am passing the item value from PostMan to get the related details of the item from D365fo.

Input from PostMan.

Response from D365FO.(Take the inputs and send the related data).

 // Return Item quantity.

Service class:

[AifCollectionType('return', Types::Class, classStr(Test2GetItemStockDataContract))]
public List GetItemStockOnHand(str itemid)
{
    TestInventTable                 testInventTable;
    InventQty                       stockOrdered,actualQty;
    InventSum                       inventSum;
    InventDim                       inventDim;
    InventDimCombination            inventDimCombination;
    EcoResDistinctProductVariant    ecoResDistinctProductVariant;
    ExtCodevalueTable               extCodevalueTable;
    InventOnhand                    inventOnhand;
    InventDimParm                   inventDimParm;
    List                            list = new List(Types::Class);
    ;

    select firstonly ecoResDistinctProductVariant
            where ecoResDistinctProductVariant.RecId == str2Int64(itemId);

    select firstonly testInventTable
            where testInventTable.ProductVariantNumber == ecoResDistinctProductVariant.DisplayProductNumber
                && testInventTable.Active == NoYes::Yes;

    if(testInventTable.RecId && ecoResDistinctProductVariant.RecId)
    {
        select firstonly inventdimcombination
                where inventdimcombination.DistinctProductVariant == ecoResDistinctProductVariant.RecId;

        inventDim.InventStyleId = inventDimCombination.inventDim().InventStyleId;
        inventDim.InventColorId = inventDimCombination.inventDim().InventColorId;
        inventDim.InventSizeId = inventDimCombination.inventDim().InventSizeId;
        inventDimParm.initFromInventDim(inventDim);

        inventOnhand    = InventOnhand::newParameters(
                            inventdimcombination.ItemId, 
                            inventDim, inventDimParm);
        stockOrdered    = inventOnhand.onOrder() + inventOnhand.reservOrdered();
        actualQty       = testInventTable.Qty - stockOrdered;

        Test2GetItemStockDataContract  data = new Test2GetItemStockDataContract();

        data.location("Test");
        data.qty(strFmt("%1",actualQty));

        list.addEnd(data);
    }
    else
    {
        Test2GetItemStockDataContract data = new Test2GetItemStockDataContract();

        data.location('Item code is invalid.');

        list.addEnd(data);
    }

    return list;

}       

Input/ OutPut.

========================================================================

 Example 3:

Here I am getting the details from the D365FO. I have created a new custom table for storing the items in D365FO. Here every Item has an active check box. My code will return only active Items.

Response from D365FO.

 // Get Active Items from invent table.

Service class:

// [AifCollectionType('return', Types::String), SysEntryPointAttribute(true)]

[AifCollectionType('return', Types::Class, classStr(Test3GetItemDetailsContract))]
public List GetItemDetails()
{
    TestInventTable         testInventTable;
    List                    resultSet = new List(Types::Class);
    ;

    while select testInventTable
        where testInventTable.Active == NoYes::Yes
    {
        Test3GetItemDetailsContract     data = new Test3GetItemDetailsContract();

        data.vendorCode(testInventTable.VendorCode);
        data.vendorPartNumber(testInventTable.ExternalItemId);
        data.productNumber(testInventTable.ItemId);
        data.productVariantNumber(testInventTable.ProductVariantNumber);
        data.productName(testInventTable.ItemName);

        //resultSet.addEnd(strFmt("vendorCode:%1,vendorPartNumber:%2,
        //                            productNumber:%3, productvariantnumber:%4,
        //                            productname:%5",
        //                        testInventTable.VendorCode,
        //                        testInventTable.ExternalItemId,
        //                        testInventTable.ItemId,
        //                        testInventTable.ProductVariantNumber,
        //                        testInventTable.ItemName));  string format

        resultSet.addEnd(data);
    }

    return resultSet;
}


Keep Daxing!!


Cannot stop DynamicsAxBatch service on computer Dynamics 365Fo

 Cannot stop DynamicsAxBatch service on computer Dynamics 365Fo.

1. Stop DynamicsAxBatch from services.

If it throw's any error. use below steps.


Open CMD with run as administrator and run the below command.


"sc queryex DynamicsAxBatch"



Get the PID number from above screen shot. and run below command.

“taskkill /f /pid [pid number]”

EX : taskkill /f /pid 000.

After this buid you're system or project.


Keep Daxing!!


Wednesday, June 9, 2021

How to get RecId selected from lookup method?

 How to get RecId selected from the lookup method?. 

public void lookup()
{
    FormRun lookupFormRun;
    Args args;
    MyTable    myLookup;

    args = new Args();
    args.name(formStr(MyNewLookupForm)); // args.caller(this);
    lookupFormRun = classFactory.formRunClass(args);
    lookupFormRun.init();
    this.performFormLookup(lookupFormRun);
    lookupFormRun.wait();
    if (lookupFormRun.closedOk())
    {
        myLookup= formRun.docCursor();
    }
}
Override 'MyNewLookupForm' (new lookup form) init method. Write below logic.
public void init()
{
     super();

     element.selectMode(MainField);
} //MainField -> This is grid field name. Set Auto decleration to Yes.
public void run() // Fileter the selected value in control.
{
    boolean filterLookup;
    FormStringControl callingControl = SysTableLookup::getCallerStringControl(
                                                                   element.args());
    /*filterLookup = SysTableLookup::FilterLookupPreRun(callingControl, 
                                                        Dinosaurs_DinosaurName, 
                                                                Dinosaurs_ds);*/
    super();
 
    SysTableLookup::FilterLookupPostRun(/*filterLookup*/true, 
                                        callingControl.text(), 
                                        Dinosaurs_DinosaurName, 
                                        Dinosaurs_ds);
}


Keep Daxing!!