Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Update Customer Status

Posted on by 572

Hi Guys,

I have a request that I need to update the customer's Classification Id to " Inactive " through a job if below three conditions are met.

1. There is no record exists in the table ForecastSales with this customer for the last 12 months ( we have fields end date and start date in this table)

2. There is no open orders for this customer Account in the sales table

3. There is nothing invoiced to this customer account for the last 12 months 

how can I check these conditions and update the customer status  through X++ Code.

Thanks in Advance.

*This post is locked for comments

  • D365  beginner Profile Picture
    D365 beginner 572 on at
    RE: Update Customer Status

    Hi Sukrut & Chaitanya,

    Thanks a lot. it works fine.

  • Verified answer
    Chaitanya Golla Profile Picture
    Chaitanya Golla 17,225 on at
    RE: Update Customer Status

    Hi,

    Please use the following job to update classification Id on the customer.

    I don't have sufficient data to test it. So, execute it and let me know if anything is missing.

    static void CustClassification(Args _args)
    {
    CustTable custTable;
    ForecastSales forecastSales;
    SalesTable salesTable;
    boolean canCreateRecord;
    TransDate startDate, endDate;
    CustInvoiceJour custInvoiceJour;
    int i;

    endDate = today();

    i = year(endDate) - 1;
    startDate = mkDate(dayOfMth(endDate), mthOfYr(endDate), i);

    while select custTable
    //where custTable.AccountNum == "XYZ"
    {
    canCreateRecord = true;

    // Condition 1: No record exists in the table ForecastSales
    select firstOnly forecastSales
    where forecastSales.CustAccountId == CustTable.AccountNum
    && forecastSales.StartDate >= startDate
    && forecastSales.EndDate <= endDate;

    if (forecastSales.RecId != 0)
    {
    canCreateRecord = false;
    }

    // Condition 2: No Open Orders
    select firstOnly salesTable
    where salesTable.InvoiceAccount == CustTable.AccountNum
    && salesTable.DocumentStatus == DocumentStatus::None;

    if (salesTable.RecId != 0)
    {
    canCreateRecord = false;
    }

    // Condition 3: There is nothing invoiced to this customer account
    select firstOnly custInvoiceJour
    where custInvoiceJour.InvoiceAccount == CustTable.AccountNum
    && custInvoiceJour.InvoiceDate >= startDate
    && custInvoiceJour.InvoiceDate <= endDate;

    if (custInvoiceJour.RecId != 0)
    {
    canCreateRecord = false;
    }

    if (canCreateRecord == true)
    {
    ttsBegin;
    custTable.selectForUpdate(true);
    custTable.CustClassificationId = "Inactive";
    custTable.update();
    ttsCommit;
    }
    }
    }

  • Suggested answer
    Chaitanya Golla Profile Picture
    Chaitanya Golla 17,225 on at
    RE: Update Customer Status

    Hi,

    There are so many ways to achieve this.One way is to calculate the start date & end date, pass the values to table buffer and loop them. I used salesTable for example and you can replace any table buffer of your choice.

    static void DateInterval(Args _args)

    {

       SalesTable salesTable;

       TransDate startDate, endDate;

       int i;

       endDate = today();

       i = year(endDate) - 1;

       startDate   = mkDate(dayOfMth(endDate), mthOfYr(endDate), i);

       while select salesTable

           where salesTable.DeliveryDate >= startDate

           && salesTable.DeliveryDate <= endDate

       {

           info(strFmt("%1", salesTable.DeliveryDate));      

       }

    }

  • D365  beginner Profile Picture
    D365 beginner 572 on at
    RE: Update Customer Status

    Hi Mahmoud / Sukrut

    Thanks for the reply, I am not familiar with the date formats in X++. how to write the code to retrieve the data between today and last 12 months.

  • D365  beginner Profile Picture
    D365 beginner 572 on at
    RE: Update Customer Status

    hi Sukrut,

    Thanks for the reply if you have time, Could you just show me 1 full example how the code should be ? considering the second point itself.

  • Suggested answer
    Mahmoud Hakim Profile Picture
    Mahmoud Hakim 17,887 on at
    RE: Update Customer Status

    you can make job in sql server and use the following code

    update CUSTTABLE  set custclassficationid = " your group" where CUSTTABLE.ACCOUNTNUM in (select distinct (c.ACCOUNTNUM) from custtable c where c.ACCOUNTNUM in(select distinct(s.CUSTACCOUNT)  from SALESTABLE s where s.SALESSTATUS =1  )

    or c.ACCOUNTNUM in (select distinct (f.CUSTACCOUNTID)  from ForecastSales f where year(f.ENDDATE) > year(GETDATE())-1  )

    or c.ACCOUNTNUM in (select distinct(v.ORDERACCOUNT) from CUSTINVOICEJOUR v where year(v.INVOICEDATE) > year(GETDATE())-1 )

    )

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans