Wednesday, 27 October 2021

D 365 FO Default password for MSSQL DB one box Environment

Hi all,

Below is the default password for the Database which we are using in the One Box Dev Environment.

       

        Username "axdbadmin" 

The default password of D365FO / AX7 VM Administrator is 'pass@word1'.

The default password of D365FO / AX7 VM Database Administrator is 'AOSWebSite@123'.

Keep DAXing :)

Sunday, 17 October 2021

D 365 FO to create Sales order from X++ Code

 Hi,

the below x++ code will help you to create the Sales Order from the code behind without any form or pop up this code can be used for creating the Sales Order for the Integration forms.


class RAM_CreateSalesOrderFromCodeBehind

{

    public static void main(Args _args)

    {        

        SalesTable salesTable;

        SalesLine salesLine;

        InventTable inventTable;

        InventDim inventDim;

        CustTable custTable;

        CustAccount custAccount;

        NumberSeq numberSeq;

        SalesId salesID;

        str warehouse;

        try

        {

            ttsbegin;

            salesTable.clear();


            numberSeq = NumberSeq::newGetNum(SalesParameters::numRefSalesId());

            numberSeq.used();

salesID = numberSeq.num();

            salesTable.SalesId = salesID;

            

            salesTable.initValue();

            

            if(CustTable::find([Customer ID]))

            {

                salesTable.CustAccount = [Customer ID];

            }

            else

            {

                info(strFmt("Customer account %1 doesn't exist.", [Customer ID]));

            }


            

            salesTable.initFromCustTable();

            if(InventLocation::find([warehouse ID]).InventLocationId != "")

            {

                salesTable.InventSiteId = InventLocation::find(warehouse).InventSiteId;

                salesTable.InventLocationId = inventlocation::find(warehouse).InventLocationId;

            }

            salesTable.insert();

            try

            {

                inventTable.clear();

                inventDim.clear();

                salesLine.clear();


                select * from inventTable

                    where inventTable.itemId == [Item ID];

                    

                salesLine.clear();

                salesLine.SalesId = salesID;

                salesLine.ItemId = inventTable.ItemId;

                salesLine.itemIdChanged();


                

                salesLine.initFromInventTable(InventTable::find(salesLine.ItemId));


                if(Inventlocation::find(warehouse).InventLocationId != "")

                {

                    inventdim.InventSiteId = InventLocation::find(warehouse).InventSiteId;

                    inventdim.InventLocationId = Inventlocation::find(warehouse).InventLocationId;

                }

                salesLine.InventDimId = InventdIm::findOrCreate(inventDim).inventDimId;


                salesLine.createLine(NoYes::Yes, // Validate

                NoYes::Yes, // initFromSalesTable

                NoYes::No, // initFromInventTable

                NoYes::Yes, // calcInventQty

                NoYes::Yes, // searchMarkup

                NoYes::Yes); //


                //Set the values as per your scenario

                salesLine.SalesPrice = [Item Sales Price];

                salesLine.SalesQty = [Qty];

                salesLine.LineDisc = [Line discount];

                salesLine.LineAmount= salesLine.calcLineAmount();

                salesLine.update();

                ttscommit;

            }

            catch(Exception::Error)

            {

                ttsabort;

            }


            

            SalesFormLetter formLetterObj;

            formLetterObj = SalesFormLetter::construct(DocumentStatus::Invoice);

            formLetterObj.update(SalesTable::find(salesID));

            

            info(strFmt("Sales order created with Sales ID: %1",salesID));

        }

        catch(Exception::Error)

        {

            ttsabort;

        }

    }

}


Keep DAXing :)

Wednesday, 6 October 2021

D 365 FO code to get the Item Price by Trade agreement (Purchase/Sales)

 Dear All,

In this post, we'll get the Item price from the Trade Agreement irrespective of Purchase or Sales Request forms.

Static method you can write in the Table or in the Extensions classes the syntax may differ if your using extension classes.

 public static Amount    findSalesItemPrice(ItemId _itemId, CustAccount _custAccount, InventDimId _inventDimId, Qty _qty)

    {

        PriceDisc                               priceDisc;

        InventTable inventTable     = InventTable::find(_itemId);

        CustTable custTable       = CustTable::find(_custAccount);

        InventDim inventDimItem   = InventDim::find(_inventDimId);

        UnitOfMeasureSymbol     unitId          = inventTable.inventTableModuleInvent().UnitId;

        Amount                   retPrice;


        priceDisc = new PriceDisc(ModuleInventPurchSales::Sales, _itemId, inventDimItem, unitId, systemDateGet(), _qty , _custAccount);


        if (priceDisc.findPrice(custTable.PriceGroup))

            retPrice = priceDisc.price();

        else if (priceDisc.findItemPrice())

            retPrice = priceDisc.price();


        return retPrice;

    }

you can Change the Customer Details to Vendor in case if your in plan to get the Item price for Puchase request forms.



Thank you

Keep Daxing:)



Tuesday, 5 October 2021

D 365 FO call the Other form by passing datasource as menu parameter

 Hi All,

in this post, we'll check how to call the Display menu Item or Form from the back end.

Step 1: Add the respective button in the existing form or new form, go to events, and copy the clicked event handler.

Sample code look alike

[FormControlEventHandler(formControlStr(SalesTable, Complete), FormControlEventType::Clicked)]

public static void Complete_OnClicked(FormControl sender, FormControlEventArgs e)

{

    // your Code       

}

now copy-paste or rewrite the below code according to your requirements.


[FormControlEventHandler(formControlStr(SalesTable, Complete), FormControlEventType::Clicked)]

public static void Complete_OnClicked(FormControl sender, FormControlEventArgs e)

{     

FormRun                             form                = sender.formRun();

        FormDataSource                      salesTable_ds        = form.dataSource(formDataSourceStr(SalesTable, SalesTable)) as FormDataSource;

   SalesTable                          salesTable = salesTable_ds.cursor();

        Args                                args;

        MenuFunction                        menuFunction;


        info(strFmt("%1",SalesStatus::None));

        if(salesTable.SalesStatus   == SalesStatus::None)

        {

            args.record(salesTable); // to send whole table as parameter

            args.caller(sender);

            menuFunction = new MenuFunction(menuItemDisplayStr(BER_CreateQuotationFromSalesOrder), MenuItemType::Display);

            menuFunction.run(args);

        }

        else

        {

            throw Error(strfmt('[LabelID]',salesTable.SalesStatus));

        }

}


Thanks

Keep Daxing :)

Monday, 4 October 2021

D 365 FO Form datasource Field Lookup in Extension Class

Hi all,

In this post, I'll explain to you how to define or add the lookup method for the Datasource field in the form by using the extension class and method.

Step 1: Go to the Field in the form for which you are willing to add the Custom lookup. Expand the Events Mouse right Click "Copy Event handled Method".

Step 2: Create a new Extension class or Paste the copied method in the new or existing extension class.

The sample code of copied method will look alike.

[FormControlEventHandler(formControlStr(SalesQuotationTable, Line_ItemId), FormControlEventType::Lookup)]
public static void Line_ItemId_OnLookup(FormControl sender, FormControlEventArgs e)
{       
}

Step 3: Copy / Type the below code  
[FormControlEventHandler(formControlStr(SalesQuotationTable, Line_ItemId), FormControlEventType::Lookup)]
public static void Line_ItemId_OnLookup(FormControl sender, FormControlEventArgs e)
{   
        Query                   query                   = new Query();
        QueryBuildDataSource    queryBuildDataSource;
        SysTableLookup          sysTableLookup;
        
        sysTableLookup = SysTableLookup::newParameters(tableNum([TableName]), sender);
        queryBuildDataSource = query.addDataSource(tableNum([TableName]));
        
        queryBuildDataSource.addRange(fieldNum([TableName], [FieldName for Filter])).value([Filter field value]);
        
        sysTableLookup.addLookupField(fieldNum([TableName], [FieldName to be selected and shown in lookup]), true);
        sysTableLookup.addLookupMethod(tableMethodStr([TableName], [FieldName to shown in Lookup]));

        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();
}

Hope this post will help you to add the Customlookup in Datasource field.


Thanks,

Keep Daxing :)