Tuesday, April 20, 2021

Remove Number sequence in Parameter form in D365Fo using X++

 

 Remove Number sequence in Parameter form in D365Fo using X++.


public static void main(Args _args)

    {

       NumberSequenceDatatype numSeqDT; // EDT information

        NumberSequenceReference numSeqRef; // Merging relation between EDT and number sequence

        select forUpdate numSeqDT

        where numSeqDT.DatatypeId == extendedtypenum(BookingID); // EDT Id

        delete_from numSeqRef

        where numSeqRef.NumberSequenceDatatype == numSeqDT.RecId;

        ttsBegin;

        numSeqDT.delete();

        ttsCommit;

        info( strFmt("Relation with EDT: %1 is removed.", numSeqDT.DatatypeId) );

    }

Keep Daxing!!

Thursday, April 15, 2021

Replace time in D365Fo using X++

 Replace time in D365Fo using X++


    public utcdatetime checkTime(utcdatetime  _dateTime)

    {

        FromTime        second      = DateTimeUtil::second(_dateTime);

        FromTime        minute      = DateTimeUtil::minute(_dateTime);

        utcdatetime     dateTime    = DateTimeUtil::addMinutes(DateTimeUtil::addSeconds(_dateTime,-second),-minute);;

        ;


        if((minute >= 15 && minute < 30) || (minute >= 30 && minute < 45))

        {

            dateTime = DateTimeUtil::addMinutes(dateTime, 30);

        }

        else if(minute >= 45 && minute < 60)

        {

            dateTime = DateTimeUtil::addHours(dateTime, 1);

        }


        return dateTime;

    }

Wednesday, April 7, 2021

Variant Lookup for Master Item In d365Fo

 

Variant Lookup for Item In d365Fo.


======================customized from(over ride method) =====================

    void lookup()

    {

        FormRun formRun = ClassFactory.formRunClass(new Args(formstr(RetailVariantLookup)));


        formRun.args().parm(itemId);

        formRun.args().caller(fieldItemId.control());//_formControl);

        formRun.init();


        //_formControl

        fieldItemId.control().performFormLookup(formRun);

    }


========================Standard form(using Events)=========================



    [FormControlEventHandler(formControlStr(SalesTable, RetailVariantId), FormControlEventType::Lookup)]

    public static void RetailVariantId_OnLookup(FormControl sender, FormControlEventArgs e)

    {

        FormControlCancelableSuperEventArgs     formControlCancelSuper  = e as FormControlCancelableSuperEventArgs;

        FormRun                                 formRun                 = ClassFactory.formRunClass(new Args(formstr(RetailVariantLookup)));

        FormStringControl                       itemId                  = sender.formRun().design().controlName(formControlStr(SalesTable, ItemCode));

        FormStringControl                       retailVariantId         = sender.formRun().design().controlName(formControlStr(SalesTable, RetailVariantId));

        ;


        formControlCancelSuper.CancelSuperCall();


        formRun.args().parm(itemId.valueStr());

        formRun.args().caller(retailVariantId);//_formControl);

        formRun.init();


        //_formControl

        retailVariantId.performFormLookup(formRun);

    }


Keep Daxing!!

Tuesday, April 6, 2021

Override JumpRef method in standard form control in D365FO

 OverRide JumpRef method in standard form cotrol in D365FO.


  • Copy Form 'OnInitialized' Event handler from standard form.

    [FormEventHandler(formStr(SMAParameters), FormEventType::Initialized)]
    public static void SMAParameters_OnInitialized(xFormRun sender, FormEventArgs e)
    {
	var                     overrides   = new TestClass();
	FormStringControl       formControl = sender.design().controlName(formControlStr(SMAParameters, FormControlName));
	
	formControl.registerOverrideMethod(methodStr(FormStringControl, jumpRef), 
                                            methodStr(TestClass, MethodName), overrides);
    }


  • In TestClass  I have created a new method and written the below code.

    public void method(FormControl _formControl)
    {
	// With Filter

	FormRun         formRun;
	Args            args            = new Args();
	FormDataSource  formDataSource  = new FormDataSource();

	args.name(formStr(formName));

	formRun = ClassFactory.formRunClass(args);
	formRun.init();
	
	formDataSource = formRun.dataSource();
	formRun.run();

	formDataSource.filter(fieldNum(TableName, FieldName), "Value");

	formRun.detach();
	
	----------------------------------------------------------------------------------

	// With out Filter
	Args            args            = new Args();
	
	args.record(common);
	
	new MenuFunction(menuitemdisplaystr(menu item name), 
				MenuItemType::Display).run(args);
	--------------------or------------------------------------------
	smmUtility::openMenuItemForm(menuitemDisplayStr(My menu item name), null, _formControl);
    }


Normal jumpref:

    public void jumpRef(FormControl _formControl)
    {
	smmUtility::openMenuItemForm(menuitemDisplayStr(My menu item name), null, this);

	-----------------------or-----------------------------------------------

	new MenuFunction(menuitemdisplaystr(menu item name), 
			MenuItemType::Display).run(args);
    }


Keep Daxing!!


How to call child form with filtered records using X++ in D365FO

 How to call Form with filtered records using X++ in D365FO.


check below code.

    =======================Using Form Run======================

    {

        Args            args = new Args();//(formStr(formName));

        FormRun         formRun;

        FormDataSource  formDataSource = new FormDataSource();

        ;

        args.name(formStr(formName));

        formRun = ClassFactory.formRunClass(args);

        formRun.init();

        formDataSource = formRun.dataSource();

        formRun.run();

        formDataSource.filter(fieldNum(TableName, FieldName), "Value");

        formRun.detach();

        -------------------------------------------------OR-----------------------------------------------

        Args args = new Args();

        args.caller(_caller);

        args.parm(_parm);


        FormRun fr = new MenuFunction(menuitemDisplayStr(FormName), MenuItemType::Display).create(args);

        fr.run();

        fr.dataSource().findRecord("Value");

        fr.detach();

    }


====================Using Menu Function===========================


    {

        MenuFunction            menuFunction;

        FormRun                 formRun;

        Args                    args = new Args();

        ;


        // args.record(TableBuffer);

        args.lookupRecord(TableBuffer); //Below 2 methods are also working same

        // args.lookupField(fieldNum(TableName, FieldName));

        //args.lookupValue('Value');

        menuFunction = new MenuFunction(menuitemDisplayStr(EcoResAttributeType), MenuItemType::Display);

        menuFunction.run(args);

    }


Keep Daxing!!

Monday, April 5, 2021

REFRESH CALLER FORM DATASOURCE FROM A CLASS IN D365FO/AX7

 REFRESH CALLER FORM DATASOURCE FROM A CLASS IN D365FO/AX7.


Please check the below code.

 private static void main(Args _args)

{

        Test                            testTable;

        TestClass                       testClass;

        FormDataSource                  formDs;

        int                             position;

        ;

        if (_args && _args.dataset() == tableNum(Test))

        {

            testTable = _args.record();

        }

        testClass = new TestClass();

        formDs = FormDataUtil::getFormDataSource(testTable);

        //formDs =  _args.record().dataSource();

        testClass.checkStage(testTable, testmethod);

        

        if (testTable.RecId && formDs)

        {

            position = formDs.getPosition();

            formDs.research();

            formDs.setPosition(position);

        }

}

Keep Daxing!!

Get on hand inventory (quantity) of an item using x++ in d365Fo

 Get on hand inventory (quantity) of an item using x++


Check below code.

static void availTotal(Args _args)

{

    InventDim       inventDim;

    InventOnhand    inventOnhand;

    InventDimParm   inventDimParm;


    inventDim.InventSiteId = '1';

    inventDim = InventDim::findOrCreate(inventDim);



    inventDimParm.initFromInventDim(inventDim);

    inventOnhand = InventOnhand::newParameters('D0001', inventDim, inventDimParm);


    info(strFmt('%1', inventOnhand.availTotal()));

}


Keep Daxing!!

Thursday, April 1, 2021

Print SSRS Barcode in D365Fo

 Print SSRS Barcode in D365Fo.


Check below code to convert your string to Barcode string :


public BarCodeString ShowBarcode(str _text) { Barcode barcode; barcode = Barcode::construct(BarcodeType::Code128); barcode.string(true, _text); barcode.encode(); return barcode.barcodeStr(); }

 

Keep daxing!!