web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

class get month only from field date

(0) ShareShare
ReportReport
Posted on by 497

i have script such as below :

tmpFixedAssetNew.JanuaryMST = (select sum(AmountMST) from assetTrans
where assetTrans.AssetId == assetBook.AssetId
&& assetTrans.BookId == assetBook.BookId
&& (assetTrans.TransType == AssetTransType::Depreciation
|| assetTrans.TransType == AssetTransType::DepreciationAdj)
&& mthOfYr(int TransDate) == 1).AmountMST;

but error with script this "mthOfYr(int TransDate) == 1"

why?

do you know it?

*This post is locked for comments

I have the same question (0)
  • Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    Hi,

    you cannot use x++ functions inside select statement.

    try to create a customized view and then you can directly use where clause with specific column of month number or name.

  • murtafiah Profile Picture
    497 on at

    hi mr sohaib,

    i was change to be mthOfYr(AssetTrans.TransDate) == 1 but still error.

    why?

    :(

  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    Use transdate as parameter instead of int TransDate, so it would be mthOfYr(TransDate) == 1.

    Declare transdate before using it.

    Refer following link:

    (mthOfYr Function [AX 2012])

    msdn.microsoft.com/.../aa603608.aspx

  • Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    as I said, previously you will.

    because where clause would not allow you use of illegal expressions such as x++ functions around a field table.

    create a view and use that as table.

  • Community Member Profile Picture
    on at

    I think you have to filter with range instead using mthOfYr by using start date and end date.

    how about like this?

    tmpFixedAssetNew.JanuaryMST = (select sum(AmountMST) from assetTrans
    
    where assetTrans.AssetId == assetBook.AssetId
    
    && assetTrans.BookId == assetBook.BookId
    
    && (assetTrans.TransType == AssetTransType::Depreciation
    
    || assetTrans.TransType == AssetTransType::DepreciationAdj) && assetTrans.TransDate >= startDate
    
    && assetTrans.TransDate <= endDate).AmountMST;


    where the startDate and endDate is from the month that you want to filter.

  • murtafiah Profile Picture
    497 on at

    Hi Mr. Yonathan,

    i want show sum(amountMST) only january or february to be 2 column is january and february.

    How?

  • Community Member Profile Picture
    on at

    Sorry Murtafiah, I am not barely understand your question, please be more specific and clear.

  • Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    As Yonathan stated, you can use daterange(i.e start date as 1/1/2017 and end date as 1/31/2017) to get the values for January. If you want to get values for February you can loop the same query by changing the values of start date and end date.

  • murtafiah Profile Picture
    497 on at

    Hi all,

    My problem was solve,

    thanks all, for the support

    :)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Sukrut Parab Profile Picture

Sukrut Parab 2 Moderator

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans