Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Query salesline (filter inventdim not working)

(0) ShareShare
ReportReport
Posted on by 60

Hi Guys,

I am working on a weird issue. I created the following functionality. I know for a fact that there is a salesline with inventdim and itemid that matches with the filters in the where clause.

If i remove the inventdimid i get a total qty of 26 instead which is right but i want to get the qty of the item / inventdimid and get that qty. i even removed all the group by and sum in the select and created this less performing query to debug it.

When i run it as a job it is working. When i run it (yes i debugged all the variables are filled i also checked _inventdimId) the query will not have any result

private void insertSalesLineInformation(ForecastItemAllocationId _allocId, ItemId _itemId, InventDimId _inventdimId, utcDateTime _baseDate)
{
    SalesLine                   salesLine;
    SalesTable                  salesTable;
    SalesQty                    salesQty;
    ForecastItemAllocationLine  forecastItemAllocationLine;
    
    ttsBegin;
    
    while select salesLine
    where salesLine.InventDimId == _inventdimId
       && salesLine.ItemId == _itemId
       && salesLine.createdDateTime >= _baseDate
       && salesLine.SalesStatus == (SalesStatus::Backorder || SalesStatus::Invoiced)
       && salesLine.SalesQty <= 10
    {
        salesQty = salesQty + salesLine.SalesQty;
    }
            if (salesQty > 0)
            {
                forecastItemAllocationLine.AllocationId     = _allocId;
                forecastItemAllocationLine.ItemId           = _itemId;
                forecastItemAllocationLine.InventDimId      = _inventDimId;
                forecastItemAllocationLine.HSOMixLines      = salesQty;

                forecastItemAllocationLine.initValue();

                if (forecastItemAllocationLine.validateWrite())
                {
                    forecastItemAllocationLine.insert();
                }
            }
ttsCommit; }

*This post is locked for comments

  • Rustem Galiamov Profile Picture
    Rustem Galiamov 8,072 on at
    RE: Query salesline (filter inventdim not working)

    You can mark question as answered if answers were helpful.

  • Jack D Profile Picture
    Jack D 60 on at
    RE: Query salesline (filter inventdim not working)

    Hi Nikolaos and Rustem,

    Both where correct. I had to take a better look into the debugger and also getting the salesline inventdimid was not correct. A functionality gave the wrong inventdimid sometimes due to not clearing a variable.

    Taking a break and start looking at the code after lunch also helped :).

    Thanks again!

  • Suggested answer
    Rustem Galiamov Profile Picture
    Rustem Galiamov 8,072 on at
    RE: Query salesline (filter inventdim not working)

    Hi Jack D!

    Just to add to previous suggestion.

    Are you sure what the salesLine has _inventDimId value? Check it in salesLine table browser because of one salesLine record can include many different inventTrans records with different inventDimId.

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Query salesline (filter inventdim not working)

    So for now we should concentrate on the select statement and forget everything that comes after that. Right? You expect your select statement to find some records based on the criteria that is passed to the method as parameters.

    You say when you run it as a job it's working. But when you run it (I assume run as part of the application process) it's not working.

    Could you debug the process and write down all method parameter values, and use the same values in the job. What is the result?

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,321 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans