Extend / Customize standard CanSubmitToWorkflow in D365


We cant override CanSubmitToWorkflow to return our boolean on any eventHandler’s return like eventHandler of ValideWrite(). To achiew we have to set the args of CanSubmitToWorkflow() to be decided by our code.

[PostHandlerFor(formStr(CustTable), formMethodStr(CustTable, canSubmitToWorkflow))]

    public static void CustTable_Post_canSubmitToWorkflow(XppPrePostArgs args)


        FormRun     form = args.getThis();

        FormDataSource      custTable_ds = form.dataSource(formDataSourceStr(custTable,CustTable)) as FormDataSource;

        custTable           custTable    = custTable_ds.cursor();

        if (custTable.RecId && custTable.DocumentStatus == DocumentStatus::NotSubmitted)

How to achieve table relation in SQL without primary index 1:n


Select particular parent table (master table) db.table.
1. Right click select design

2. Select the respective field where we have to achieve unique index but not primary.
Right click on that filed select Indexs/keys…

3. Add the select the column to from that list and please make sure you change the property to YES in isUnique.

4. Save and select the design of transaction table where we try to achive Foreign key.
Right click on that particular filed and choose Relationships..

5. Add the relationship by select the tables and columns specifics.


RandomNumbers In AX /D365


static void CreateRandomNumbersInAX(Args _args)


    RandomGenerate randomGenerate;


    randomGenerate = RandomGenerate::construct();

    randomGenerate.parmSeed(new Random().nextInt());

    info(int2str(RandomGenerate.randomInt(0,2147483647)));   //RandomInt(RangeFrom,RangeTo)

    //Note: Range from should be more than natural number 0 and more.


Round the decimals (upper / lower) in AX 2012 / D365


static void AlfRound(Args _args)


    Amount  amount = 5578.59;

    info(strfmt(“Amount %1”, amount)); // Printing the original values

    info(strfmt(“Round,1  – %1”, round(amount,1))); // This performs standard operation of round and removes the decimal.

    info(strfmt(“roundDown,1 – %1”, roundDown(amount,1)));  //Always round by down with ones position, if you make 100 then output will be 5,500.00

    info(strfmt(“roundDownDec,1 – %1”, roundDownDec(amount,1))); // Down rounding only the decimal values

    info(strfmt(“roundUpDec,1 – %1”, roundUpDec(amount,1))); //Up rounding only the decimal values

    info(strfmt(“roundup,1 – %1”, roundup(amount,1))); //Always round by down with ones position, if you make 100 then output will be 5,600.00

    info(strfmt(“roundUp(roundUp,1) – %1”, roundUp(roundup(amount,1),1))); // Roud the rounded amount will not make any changes in the rounded amount.

    info(strfmt(“decround,1 – %1”, decround(amount,1))); // It performs the standard operation of round in decimal 


Minumum and Maximum date in AX 2012 / D365


// Minimum dateTime and Maximum DateTime

    utcdatetime                 minDateTime = DateTimeUtil::minValue();

    utcdatetime                 maxDateTime = DateTimeUtil::maxValue();

// Minimum date and Maximum Date

    TransDate                 minDate = dateNull();

    TransDate                 maxDate = dateMax();


Marshaling Webservices enum to X++ during integration


    NICServiceLibrary.EltezamServiceRef.GenderType           M,F,N;

    M = NICServiceLibrary.EltezamServiceRef.GenderType::M;

    F = NICServiceLibrary.EltezamServiceRef.GenderType::F;

    N = NICServiceLibrary.EltezamServiceRef.GenderType::N;




SSRS reports prompts for user credentails in Dynamics AX / 365


If you experience anytime SSRS reports prompts for user credentails in Dynamics AX / 365, then the respective datasets in report may use type of AXREPORTDATAPROVIDER / AXQUERY doesn’t parse the users credentails during report run time to DataSource in SSRS DB (ReportServer).

Integrated Windows Authentication(IWA) is the microsoft authentication protocal, using windows login credentials to autheticate the Microsoft product. In Dynamics AX 2009 / 2012 R2 / 2012 R3 uses IWA. If an application is not opening or running close and reopens same way we needs to to SSRS too.

Solution: We needs refresh the credentails flow, so drop the contents in reports folder and recreate and redeploy all the reports


Working on Visual Studio 2013 for Dynamics AX 2012 R3 development.


Morphx is the Microsoft Dynamics AX development environment, We all the developers are familiar with this development environment. Only SSRS and retails developments are going on Visual studio, whereas Microsift Dynamics AX 2012 R3 CU 13 support Visual Studio as development environment.

Microsoft Dynamics AX and Visual Studio are integrated through Visual Studio Tools. VS Tools is a enables the AOT objects in VS for the development for Microsoft Dynamics AX.

The AOT objects are IDE(Integrated Development Environment) with VS by VS tools.

For more details click here


Get main account from dimension in D365




Seperate dimension value from financial dimension in D365 / AX 2012 R3

public static DimensionValue getDimensionValue(int64 _dimension,
                                                                                            DimensionValueName _dimAttribute)
     DimensionAttributeValueSetStorage     dimensionAttributeValueSetStorage;
     dimensionAttributeValueSetStorage  = DimensionAttributeValueSetStorage::find(_dimension);
     return dimensionAttributeValueSetStorage.getDisplayValueByDimensionAttribute( DimensionAttribute::findByName(_dimAttribute).RecId);

HcmPositionHirarchy To whom position needs to report in upper ranking in AX 2012 / D365


static void AlfPositionHirarchyUP(Args _args)
    HcmWorker                   HcmWorker;
    HcmPositionWorkerAssignment HcmPositionWorkerAssignment;
    HcmPositionHierarchy        HcmPositionHierarchy;
    HcmPositionRecId            positionRecId;
    positionRecId = HcmPosition::findByPosition(HcmWorker::findByPersonnelNumber(‘701027’)

    select * from HcmPositionHierarchy
        where HcmPositionHierarchy.Position ==positionRecId;

    positionRecId=HcmPositionHierarchy.ParentPosition ;
        print HcmWorker::find(HcmPosition::getReportsToWorker(HcmPositionHierarchy.Position))

HcmPositionHirarchy under a position in AX 2012 /D365

Hi, static void AlfPositionHirarchyDown(Args _args){    HcmWorker                   HcmWorker;    HcmPositionWorkerAssignment HcmPositionWorkerAssignment;    HcmPositionHierarchy        HcmPositionHierarchyMan,HcmPositionHierarchy;    HcmPositionRecId            positionRecId;      positionRecId = HcmPosition::findByPosition(HcmWorker::findByPersonnelNumber(‘701027’).primaryPositionId()).RecId;     while select HcmPositionHierarchy where HcmPositionHierarchy.ParentPosition == positionRecId    {        print HcmWorker::find(HcmPosition::getWorker(HcmPositionHierarchy.Position)).name();    […]

DateTime Handlings in AX 2012 / D365

static void AlfTimeAdd(Args _args)
    TransDateTime    d = DateTimeUtil::getSystemDateTime();
    TransDate       d3 = today();
    TransDateTime    d1,d2;
    print d;
    print d3;
    d1 = DateTimeUtil::addHours(d,4); // To add 4 hours from current time
    print d1;
    d2 = Datetimeutil::newDateTime(d3,7.5*60*60); // I need today 7.30 Am
    print d2;
    print DateTimeUtil::addHours(d,4);
    print DateTimeUtil::addDays(d,4);
    print DateTimeUtil::addMinutes(d,4);
    print DateTimeUtil::addMonths(d,4);
    print DateTimeUtil::addYears(d,4);

X++ Code to handle workflow event hander for current record


public void changeRequested(WorkflowElementEventArgs  _workflowElementEventArgs)

.parmRecId(), true));
    DpayWorkerReqTable.Status = DpayWorkflowStatus::NotSubmitted;

ERROR : Update is not allowed without specifying ValidTimeStateUpdateMode in AX 2012 / D365


Add tableName.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);

inside the tts.

static void Job511(Args _args)
    EmplContract     emplContract;
    utcdatetime minDateTime = DateTimeUtil::minValue() , maxDateTime = DateTimeUtil::maxValue();
    While select forUpdate
        * from emplContract
            where emplContract.AnnualLeave == “”
        emplContract.AnnualLeave = “اجازة السنوية”;

ValidTimeState in child table relation in AX 2012 / D365


   while select validTimeState(AsOnToday) * from hcmEmployment join hcmWorker
        where  hcmWorker.RecId == hcmEmployment .Worker &&
      hcmWorker.PersonnelNumber == “1269”
        print hcmEmployment .ValidFrom;