Alfasith AX

Alfasith AX
اللَّهُمَّ انْفَعْنِي بِمَا عَلَّمْتَنِي، وَعَلِّمْنِي مَا يَنْفَعُنِي، وَزِدْنِي عِلْمًا

Monday, December 23, 2019

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);
     
    pause;
}

static void AlfaTime(Args _args)
{
    str t = "25 12 2019 10:06:00 AM";
    str t1 = "25/12/2019 10:06:00 AM";
    str t2 = "25-12-2019 10:06:00 AM";
    str t3 = "25-Dec-2019 10:06:00 AM";
    ;
    print str2datetime(t,123);
    print str2datetime(t1,123);
    print str2datetime(t2,123);
    print str2datetime(t3,123);
    print  str2datetime("2 25 1985 11:04:59 pm" ,213 );
    pause;

}

Saturday, December 21, 2019

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

Hi

public void changeRequested(WorkflowElementEventArgs  _workflowElementEventArgs)
{
    ttsbegin;

    DpayWorkerReqTable::findRecId(_workflowElementEventArgs.parmWorkflowContext().parmRecId(), true));
    DpayWorkerReqTable.Status = DpayWorkflowStatus::NotSubmitted;
    DpayWorkerReqTable.update();
    ttscommit;
}

Wednesday, October 23, 2019

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

Hi,

Add tableName.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
 
inside the tts.

static void Job511(Args _args)
{
    EmplContract     emplContract;
    utcdatetime minDateTime = DateTimeUtil::minValue() , maxDateTime = DateTimeUtil::maxValue();
    ttsBegin;
    While select forUpdate
        * from emplContract
            where emplContract.AnnualLeave == ""
    {
        emplContract.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
        emplContract.AnnualLeave = "اجازة السنوية";
        emplContract.update();
    }
    ttsCommit;
}

Regards

Delete RunbookID from AXUpdateInstaller.exe List in VM

Hi,

Please go to the path C:\Logs\InstallationRecords\Runbooks\

Delete whichever RunBooks to be removed from the server.

Regards,

Sunday, September 29, 2019

ValidTimeState in child table relation in AX 2012 / D365

Hi,

   while select validTimeState(AsOnToday) * from hcmEmployment join hcmWorker
        where  hcmWorker.RecId == hcmEmployment .Worker &&
      hcmWorker.PersonnelNumber == "1269"
    {
        print hcmEmployment .ValidFrom;
    }
    pause;
}

Regards

Tuesday, September 24, 2019

Tuesday, September 3, 2019

User ID to user name or Worker Name in AX 2012 / D365

Hi,

Worker = HcmWorker::find(DirPersonUser::findUserWorkerReference(UserId));

or

    public display Name userName()
{
    DirPartyName        partyName;

    partyName = DirPersonUser::userId2Name(this.UserId);
    if (!partyName)
        partyName = (select firstonly Name from userInfo where userInfo.Id == this.UserId).Name;
    if (!partyName)
        partyName = this.UserId;
    return partyName;
}


Regards

Monday, September 2, 2019

Assembly containing type Microsoft.Dynamics.AX.Framework.Tools.DMF.ServiceProxy.DmfEntityProxy is not referenced

Hi,

Error: "Assembly containing type Microsoft.Dynamics.AX.Framework.Tools.DMF.ServiceProxy.DmfEntityProxy is not referenced"

It clearly says that no reference found.

Solution:

DMF is not installed.

Regards,

Thursday, August 29, 2019

Sum, Avg, Count, Max, Min functionalities in Query class in AX 2012 / D365

Hi,



Regards,

Relation between HcmPositionDetail, HcmPositionWorkerAssignment, HcmWorker for query class in AX 2012 / D365

Hi,

    Query                   query = new Query();
    QueryRun                queryRun;
    QueryBuildDataSource    qbdsHcmWorker, qbdsHcmPosition, qbdsHcmPositionDetail, qbdsHcmPositionWorkerAssign;
    QueryBuildRange         qbrWorker,qbrdDept;
    HcmPositionDetail       hcmPositionDetail;
    HcmWorker               hcmWorker;
;

    qbdsHcmWorker = query.addDataSource(tableNum(HcmWorker));

qbdsHcmWorker.addRange(fieldnum(HcmWorker,PersonnelNumber)).value('1020');

    qbdsHcmPositionWorkerAssign = qbdsHcmWorker.addDataSource(tableNum(HcmPositionWorkerAssignment));

    qbdsHcmPositionWorkerAssign.relations(false);

    qbdsHcmPositionWorkerAssign.joinMode(JoinMode::InnerJoin);

    qbdsHcmPositionWorkerAssign.addLink(fieldnum(HcmPositionWorkerAssignment,Worker),fieldnum(HcmWorker,Worker));

    //qbdsHcmPositionWorkerAssign.addRange(fieldnum(HcmPositionWorkerAssignment,ValidTo)).value(SysQuery::range(today(), dateMax()));

    qbdsHcmPositionDetail = qbdsHcmPositionWorkerAssign.addDataSource(tableNum(HcmPositionDetail));

    qbdsHcmPositionDetail.relations(false);

    qbdsHcmPositionDetail.joinMode(JoinMode::InnerJoin);
    qbdsHcmPositionDetail.addLink(fieldnum(HcmPositionWorkerAssignment,Position),fieldnum(HcmPositionDetail,Position));
    qbdsHcmPositionDetail.addRange(fieldnum(HcmPositionDetail,ValidTo)).value(date2str(dateMax(), 321, DateDay::Digits2, DateSeparator::Hyphen, DateMonth::Digits2, DateSeparator::Hyphen, DateYear::Digits4));

    queryRun    = new queryrun(query);

    while(queryrun.next())

    {

        hcmWorker        = queryRun.get(tableNum(HcmWorker)) as HcmWorker;

        hcmPositionDetail           = queryRun.get(tableNum(HcmPositionDetail)) as HcmPositionDetail;

        info(strFmt("%1-%2",hcmWorker.PersonnelNumber, OMOperatingUnit::findbyRecid(hcmPositionDetail.Department).Name));

    }
*****************************************************************************

display Description getWorkerPosition()
{
    HcmWorker                                    hcmWorker;
    HcmPositionWorkerAssignment   workerAssignment;
    HcmPosition                                  hcmPosition;
    HcmPositionDetail                        hcmPositionDetail;

    select worker, position from workerAssignment
       where workerAssignment.Worker == this.RecId
       join recid from hcmPosition
       where hcmPosition.RecId == workerAssignment.Position
       join position, description from hcmPositionDetail
       where hcmPositionDetail.Position == hcmPosition.RecId;

    return hcmPositionDetail.Description;
}


Regards

Sum() in Query class in AX 2012 / D365

Hi,

To perform sum() function in Query Class.

qbdsOverTimeTrans.addSelectionField( fieldnum( DAPOvertimeTransactions, Amount), SelectionField::Sum);

Regards,

Tuesday, August 27, 2019

QueryBuildRange class to filter with never date in AX 2012 or D365

Hi,

qbdsHcmPositionDetail.addRange(fieldnum(HcmPositionDetail,ValidTo)).value(date2str(dateMax(), 321,  DateDay::Digits2, DateSeparator::Hyphen, DateMonth::Digits2, DateSeparator::Hyphen, DateYear::Digits4));
This is used for Valid Time State Tables particularly.

Regards,


Greater than or euqal to / Less than or equal to (<= or >=) in Query class in AX 2012 or D365

Hi,

Greater than or equal to:

queryBuildDataSource.addRange(fieldNum(HcmPositionWorkerAssignment,ValidTo));
        queryBuildRange.value(SysQuery::range(today(), dateMax()));

or

queryBuildDataSource.addRange(fieldNum(HcmPositionWorkerAssignment,ValidTo));
        queryBuildRange.value((queryRange(today(), dateMax()));

Less than or equal to:

 queryBuildDataSource.addRange(fieldNum(HcmPositionWorkerAssignment,ValidTo));
        queryBuildRange.value(SysQuery::range( dateNull(), today()));

or

queryBuildDataSource.addRange(fieldNum(HcmPositionWorkerAssignment,ValidTo));
        queryBuildRange.value((queryRange(dateNull(), today())); 

Regards,

Thursday, July 25, 2019

Convert Ledger dimension from ProjectID to LedgerJournalTable in AX 2012

Hi,

//for default account:
print DimensionStorage::getDefaultAccount(54154515402);//mainAccount.RecId);

DimensionStorage::accountNum2LedgerDimension(ProjId, LedgerJournalACType::Project);

Regards,

Time null in AX 2012 / D365

Hi,

There is no timeNull() unline dateNull() in Ax 2012, where as there is an work around to handle this as timeMin() or TimeMax().

DateTimeUtil::time(dateTimeUtil::minTime());  // prints 12:00 AM
DateTimeUtil::time(dateTimeUtil::maxTime());  // prints 11:59 PM

Regards,

Sunday, July 21, 2019

Wednesday, June 26, 2019

Getting current user languague in SSRS in AX 2012

Hi,

=iif(Parameters!AX_RenderingCulture.Value = "ar",FALSE,TRUE)

Note:  No needs to validate using controller class or passing the values in DP class for this.

In my case, I needs to change the order ofcolumn of the table in SSRS without reference to arabic from right to left and rest left to right.

So I added visibity based on expression on both the lines as Arabic and rest

Monday, June 17, 2019

Get the current user worker Information

Hi,

this.ChangedBy = HcmWorker::find(DirPersonuser::findUserWorkerReference(curUserId())).RecId;

Regards,

Tuesday, June 11, 2019

Add *.dll to the GAC - Global assembly cache for Windows Server 2012 or later - Using Developer CMD Prompt for Visual Studio.

Hi,


Installing the assemble in to global cache

What is GAC
           The Global Assembly Cache is a machine-wide store used to hold assemblies that are intended to be shared by several applications on the machine. Each computer where the common language runtime (CLR) is installed has a global assembly cache.

How to load/ Add *.dll
I needs load my custom *.dll files developed in dotnet to be used in AX or application wide.

This can be achieved in multiple ways like.

 1. Power-shell commands.
 2. CMD prompt.
 3. Developer CMD Prompt for Visual Studio.
 and few more

This post is using CMD Prompt

i.e calling Global assembly cache tool.

 1. Run CMD prompt as administrator
 2. Mention your dll path in targetPath.
 3. Mention your dll name in highlighted text with the extension as .dll


gacutil.exe /i "$TargetPath" /f /nologo
gacutil /i "$hello.dll" /nologo

Regards

Add *.dll to the GAC - Global assembly cache for Windows Server 2012 or later - Using CMD prompt

Hi,


Installing the assemble in to global cache

What is GAC
           The Global Assembly Cache is a machine-wide store used to hold assemblies that are intended to be shared by several applications on the machine. Each computer where the common language runtime (CLR) is installed has a global assembly cache.

How to load/ Add *.dll
I needs load my custom *.dll files developed in dotnet to be used in AX or application wide.

This can be achieved in multiple ways like.

 1. Power-shell commands.
 2. CMD prompt.
 3. Developer CMD Prompt for Visual Studio.
 and few more

This post is using CMD Prompt i.e calling Global assembly cache tool.

 1. Run CMD prompt as administrator
 2. Setting your VS SDK path in first line
 3. Mention your dll path in targetPath.
 4. Mention your dll name in highlighted text with the extension as .dll

cd C:\Program Files\Microsoft Visual Studio 8\SDK\V2.0\Bin
gacutil.exe /i "$TargetPath" /f /nologo
gacutil /i "$hello.dll" /nologo

Regards

Add *.dll to the GAC - Global assembly cache for Windows Server 2012 or later - Using Powershell

Hi,

Installing the assemble in to global cache

What is GAC
           The Global Assembly Cache is a machine-wide store used to hold assemblies that are intended to be shared by several applications on the machine. Each computer where the common language runtime (CLR) is installed has a global assembly cache.

How to load/ Add *.dll
I needs load my custom *.dll files developed in dotnet to be used in AX or application wide.

This can be achieved in multiple ways like.

1. Power-shell commands.
2. CMD prompt.
3. Developer CMD Prompt for Visual Studio.
and few more

This post is using power-shell.

1. Run windows powershell as administrator
2. Execute the below code with setting your path in first line
3. Mention your dll name in highlighted text with the extension as .dll
4. Remember to restart IIS

Set-location "D:\Dll"
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")            
$publish = New-Object System.EnterpriseServices.Internal.Publish            
$publish.GacInstall("D:\Dll\Ax2Json.dll")            
iisreset


Regards,

Monday, February 25, 2019

COC for class methods in D365

Hi,


COC- Chain of Commands are used to override the Application suite objects.
In certain cases, like the code with public and protected access specified methods cannot be created a post or pre event handler by coping its event.
In that case we need to go with COC.

This can be achieved by using the keyword ExtensionOf() to load the object and next() as super.
Note: COC class needs to final and method that to be COC can be public access specifier.
Example. COC of form button event.
//[ExtensionOf(ClassStr(ClassName)]
[ExtensionOf(classStr(SalesLineType))]
final class SalesLineType_Extension
{
    public void insert(boolean dropInvent, boolean findMarkup, Common childBuffer, boolean _skipCreditLimitCheck)
    {
        CustTable   custTable;       
        custTable = CustTable::find(salesLine.CustAccount);
        if(!custTable.CreditRating)
        {
             //Your  code to perform action before the event;
        }
        next insert(dropInvent, findMarkup, childBuffer, _skipCreditLimitCheck);       
              //Your  code to perform action After the event;
    }
}

Note: Please make sure you are creating methods with same number arguments and same pattern of arguments as well to the calling methods ie next.


Regards

COC for formDataSourceField methods in D365

Hi,


COC- Chain of Commands are used to override the Application suite objects.
In certain cases, like the code with public and protected access specified methods cannot be created a post or pre event handler by coping its event.
In that case we need to go with COC.

This can be achieved by using the keyword ExtensionOf() to load the object and next() as super.
Note: COC class needs to final and method that to be COC can be public access specifier.
Example. COC of form button event.



Similarly for all the places like datasource field level methods like modified() as
// [ExtensionOf(formDataFieldStr (FormName, TableName, FieldName)]
[ExtensionOf(formDatasourceStr(PurchTable, PurchTable, PurchDate)]
                Final class COCPurchTable_Extension
{
                Public void modified()
{
//Your  code to perform action before the event;
Next modified();
//Your  code to perform action before the event;
}
}


Regards,

COC for formDataSource methods in D365


Hi,
COC- Chain of Commands are used to override the Application suite objects.
In certain cases, like the code with public and protected access specified methods cannot be created a post or pre event handler by coping its event.
In that case we need to go with COC.

This can be achieved by using the keyword ExtensionOf() to load the object and next() as super.
Note: COC class needs to final and method that to be COC can be public access specifier.
Example. COC of form button event.
Similarly for all the places like datasource methods like insert() as
// [ExtensionOf(formDatasourceStr (FormName, TableName)]
[ExtensionOf(formDatasourceStr(PurchTable, PurchTable)]
Final class COCPurchTable_Extension
{
                Public void insert()
{
//Your  code to perform action before the event;
Next insert();
//Your  code to perform action before the event;
}
}
Regards,

COC for form object methods in D365


Hi,
COC- Chain of Commands are used to override the Application suite objects.
In certain cases, like the code with public and protected access specified methods cannot be created a post or pre event handler by coping its event.
In that case we need to go with COC.

This can be achieved by using the keyword ExtensionOf() to load the object and next() as super.
Note: COC class needs to final and method that to be COC can be public access specifier.
Example. COC of form button event.
//[ExtensionOf(formControlStr(FormName, ControlName)]
                [ExtensionOf(formControlStr(PurchTable, Total)]
                Final class COCPurchTable_Extension
                {
                                Public void clicked()
                                {
//Your  code to perform action before the event;
                                                info("COC is called");
                                                next clicked();
//Your  code to perform action before the event;
                                }
                }
Regards,

Friday, January 25, 2019

Getting the field Name in Table modified field event handler in D365

Hi,

can be achieved by args.getArgNum(1);

class XXXXCustTable_EventHandler
{
    /// <summary>
    ///
    /// </summary>
    /// <param name="args"></param>
    [PostHandlerFor(tableStr(CustTable), tableMethodStr(CustTable, modifiedField))]
    public static void CustTable_Post_modifiedField(XppPrePostArgs args)
    {
        CustTable               custTable   =  args.getThis() as CustTable;

        switch (args.getArgNum(1))
        {
            case fieldNum(custTable, CustGroup):
                if(!CustTable.OverrideSpecialMarginCode)
                {
                    custTable.SpecialMarginCode = CustGroup::find(
                                  custTable.CustGroup).SpecialMarginCode;
                }
                break;
        }
    }

}
Thanks,

Wednesday, January 23, 2019

ERROR: Abnormal termination with unhandled exception. in D365


Hi,

Please restart the IIS to fix this error.

Solution:
Using CMD  prompt, run as administrator and issreset.


Thanks,

Monday, January 21, 2019

Table browser job in D365


Hi,

This is not similar to AX 2012, we needs to invoke it like how we are opening the table browser.

1. Select the table name,
2. Call the below URL with your instance URL and table name.

https://<instanceURL>/?mi=SysTableBrowser&tableName=YYYNumberSeqLoad&cmp=YYY

https://URL/?mi=SysTableBrowser&tableName=PdsApprovedVendorList&cmpECOP&cmp=ECOP

Regards


Friday, January 18, 2019

String text case handlings in D365

Hi,

str2Capital  Convert the very first letter to caps.

str2Capital("the greater chennai")
The greater chennai.


str2CapitalWord  Convert all the first letter of the words to caps   

str2CapitalWord("the greater chennai")
The Greater Chennai.

Regards,

Wednesday, January 16, 2019

Filename handling in X++

Hi,

Check the file existance,
System.IO.File::Exists(fileName)

Copy the file A to B
System.IO.File::Copy(fileName, FileB);

Delete the file
System.IO.File::Delete(fileName);

Get only file name from the path URL.

System.IO.Path::GetFileName(fileName);
System.IO.Path::GetFileNameWithoutExtension();
System.IO.Path::GetExtension(fileName);

Regards,

How find size of recordsortedlist in D365/AX 2012

Hi, This is the continuity of the previous article where we are now getting the size of recordsortedlist . if(recordsortedlist.len() >1) ...